Skip to content

Suda97/simple_rest_api

Repository files navigation

Simple REST API

This application is a simple REST API made in Django.
It's using HTTP methods to do various operations in database.
To run it You have to install Django 4.0 and "requests" library.
App Name: Vehicle
To start application locally type in terminal: python3 manage.py runserver

POST /cars

It will check if given model exists in external database https://vpic.nhtsa.dot.gov/api/ .
If exists: The given model and maker will be saved in local database.
Else: It will return an error (404).

Local example:
curl -X POST -H "Content-Type: application/json" -d '{"make":"Honda", "model":"del Sol"}' http://127.0.0.1:8000/vehicle/cars
Heroku example:
curl -X POST -H "Content-Type: application/json" -d '{"make":"Honda", "model":"del Sol"}' https://simple-rest-api.herokuapp.com/vehicle/cars

DELETE /cars/{ id }/

It will check if vehicle with a given id exists in local database.
If exists: Vehicle with a given id will be delete from database.
Else: It will return an error (404).

Local example:
curl -X DELETE http://127.0.0.1:8000/vehicle/delete/15/
Heroku example:
curl -X DELETE https://simple-rest-api.herokuapp.com/vehicle/delete/15/

POST /rate

It will check if vehicle with a given id exists in local database.
If exists: Number of rates will be incremented by one and average rating will be recalculated for new value.
Else: It will return an error (404).

Local example:
curl -X POST -H "Content-Type: application/json" -d '{"car_id":10, "rating":2}' http://127.0.0.1:8000/vehicle/rate
Heroku example:
curl -X POST -H "Content-Type: application/json" -d '{"car_id":10, "rating":2}' https://simple-rest-api.herokuapp.com/vehicle/rate

GET /cars

It will return list of all cars from local database

Local example:
curl -X GET http://127.0.0.1:8000/vehicle/cars
Heroku example:
curl -X GET https://simple-rest-api.herokuapp.com/vehicle/cars

GET /popular

It will return list of all cars from local database ordered by number of rates in descending order

Local example:
curl -X GET http://127.0.0.1:8000/vehicle/popular
Heroku example:
curl -X GET https://simple-rest-api.herokuapp.com/vehicle/popular

About

Simple Django rest api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages