CRUD APIs for pizza db, in django
These were my python configs at the time of making this project:
python version: 3.8.10
pip version: 20.0.2
Clone this repo and run the following commands on your terminal:
$ pip install -r requirements.txt
$ python3 manage.py runserver
If the server does not start, try the following commands:
$ python3 manage.py makemigrations
$ python3 manage.py migrate
$ python3 manage.py runserver
If the server still does not start, google your error :)
After your server starts, visit localhost:8000/admin
and use the following credentials to checkout the database
username: admin
password: internship@2021
The 'Pizza' db has the following fields:
title
: string; stores the title of the pizzatype
: string; stores the type of the pizza; "Regular" or "Square"size
: string; stores the size of the pizza; "Small" or "Medium" or "Large"toppings
: string; stores the toppings on the pizza; stored in a list of stringsslug
: string; auto-generated; stores a unique name for each pizza; used to search a pizza in the db
There are in total 7 apis in this project.
-
GET | (all)
http://127.0.0.1:8000/pizzas
Expects: Nothing
Response: Lists all the pizzas in the database -
GET | (individual)
http://127.0.0.1:8000/pizza/<slug>
Expects: The slug of the pizza you want to see instead of the "< slug >" part above mentioned api.
(Eg.:http://127.0.0.1:8000/pizza/paneer-pizza-square
)
Response: Displays the details of the individual Pizza -
GET | (filtered by size)
http://127.0.0.1:8000/all_size/<size>
Expects: The size of the pizza
{Currently, only "Small", "Medium", "Large" are supported, entering a size any other than this will return an error 400}
Response: Returns all the pizzas with the requested size -
GET | (filtered by type)
http://127.0.0.1:8000/all_type/<type>
Expects: The 'type' of the pizza
{Currently, only "Regular" and "Square" types are supported, sending any other type other than these will return a 400 error}
Response: Returns all pizzas with the requested type -
PUT | (Edit/Update)
http://12.0.0.1:8000/update/<slug>
Expects: The slug of the pizza you want to update should replace the "< slug >" in the above mentioned api. The body should consist of the following fields:
title (str)
type (str)
size (str)
toppings (str)
Response: Returns the updated value of the Pizza
-
DELETE | (Delete a pizza)
http://127.0.0.1:8000/delete/<slug>
Expects: The slug of the pizza you want to delete should replace the "< slug >" in the above mentioned api.
Response: "Delete Succesfull" if the pizza is deleted, "Delete Failed" if the pizzas was not found in the database. -
POST | (Create)
http://127.0.0.1:8000/createPizza
Expects: The following fields in the body of the api request:
title (str)
type (str)
size (str)
toppings (str)
Response: Returns the details of the created pizza, if the creation was succesfull.
You can test the above mentioned APIs in Postman or anywhere you like! :)
Kushagra Wadhwa
Delhi Technological University (DTU)
( [email protected] )
print("Happy Coding!)