Bruuuum!
Prerequisites
In order to run the application locally you have to have docker
along with docker-compose
installed on your machine.
Run application locally
Run it with the following:
docker-compose up -d
and docker will take care about the rest.
API usage
1. Cars
POST /cars
1.1 Request:
curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d "{\"make\": \"honda\", \"model\": \"civic\"} 0.0.0.0:8000/cars
Response:
{
"make" : "honda",
"model" : "civic",
}
Status code: 201 CREATED
Note: All names of make or model will be lowercased.
GET /cars
1.2 Request:
curl -X GET -H "Content-Type: application/json;charset=UTF-8" 0.0.0.0:8000/cars
Response:
[
{
"id" : 1,
"make" : "Volkswagen",
"model" : "Golf",
"avg_rating" : 5.0,
},
{
"id" : 2,
"make" : "Volkswagen",
"model" : "Passat",
"avg_rating" : 4.7,
}
]
Status code: 200 OK
DELETE /cars/<id>
1.3 Request:
curl -X DELETE -H "Content-Type: application/json;charset=UTF-8" 0.0.0.0:8000/cars/2
Response:
Blank response with status code 204 NO CONTENT
2. Rate
POST /rate
2.1 Request:
curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d "{\"car_id\": 1, \"rating\": 5} 0.0.0.0:8000/rate
Response:
{
"car_id" : 1,
"rating" : 5,
}
Status code: 201 CREATED
3. Popular
GET /popular
3.1 Request:
curl -X GET -H "Content-Type: application/json;charset=UTF-8" 0.0.0.0:8000/popular
Response:
[
{
"id" : 1,
"make" : "Volkswagen",
"model" : "Golf",
"rates_number" : 100,
},
{
"id" : 2,
"make" : "Volkswagen",
"model" : "Passat",
"rates_number" : 31,
}
]
Status code: 200 OK
Ideas for further development
- There can be installed
drf_yasg
package for Swagger generation. - Tests can be parametrized using e.g.
pytest.mark.parametrize
to keep code DRY. - Tests for case when there is no internet and you cannot confirm the existence of given model.
- Separate services in
docker-compose
for bothdev
andproduction
.