recipe-rest-api

Avatar of CHU-TE, CHEN.
Avatar of CHU-TE, CHEN.

recipe-rest-api

Research Assistant
Taipei City, Taiwan

A django-based restful API to store and fetch recipes. Users can create their own recipes, ingredients, tags, and images through this API.

  • This app consists of 3 components: core, recipe, and user.
  • In the core components, we set up the model and test for our data, such as users, ingredients, tags, and recipes.
  • In the recipe component, we created an API for manipulating our models.
  • In the user components, we configured the authentication setting.
  • This app is created by using django-rest-framework.
  • Docker is applied to handle infra set up.
  • Data is stored in PostgreSQL.
  • We used test-driven-development strategies to develop, and implemented by django test.
  • We configured Travis-CI to automate code checks.
  • The API is presented in the Swagger/OpenAPI 2.0 format.
  • Json Web Token (JWT) authentication is applied to ensure users access security.
  • We used flake8 to ensure the lint and code format.

Github code: https://github.com/Jordon-Chen/recipe-app-api

Installation

docker-compose up

Test & Lint

docker-compose run --rm app sh -c "python manage.py test && flake8"

Docs

http://localhost:8000/swagger/

Usage

Create a user

curl -X POST "http://localhost:8000/api/user/create/" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"email\": \"[email protected]\",  \"password\": \"password\",  \"name\": \"user\"}"
{"email":"[email protected]","name":"user"}

Get access token

curl -X POST "http://localhost:8000/api/user/token/" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"email\": \"[email protected]\",  \"password\": \"password\"}"
{"token":"4037d08542ee003d9f59dac2b8e7b06f544d5817"}

Post ingredient

curl -X POST "http://localhost:8000/api/recipe/ingredients/" -H  "accept: application/json" -H  "Authorization: Token 4037d08542ee003d9f59dac2b8e7b06f544d5817" -H  "Content-Type: application/json" -d "{  \"name\": \"egg\"}"
{"id":1,"name":"egg"}

Post tag

curl -X POST "http://localhost:8000/api/recipe/tags/" -H  "accept: application/json" -H  "Authorization: Token 4037d08542ee003d9f59dac2b8e7b06f544d5817" -H  "Content-Type: application/json" -d "{  \"name\": \"breakfast\"}"
{"id":1,"name":"breakfast"}

Post recipe

curl -X POST "http://localhost:8000/api/recipe/recipes/" -H  "accept: application/json" -H  "Authorization: Token 4037d08542ee003d9f59dac2b8e7b06f544d5817" -H  "Content-Type: application/json" -d "{  \"title\": \"Sunny-side-up egg\",  \"ingredients\": [1],  \"tags\": [1],  \"time_minutes\": 5,  \"price\": \"1.00\",  \"link\": \"https://www.cookinglight.com/recipes/pristine-sunny-side-up-eggs\"}"
{"id":1,"title":"Sunny-side-up egg","ingredients":[1],"tags":[1],"time_minutes":5,"price":"1.00","link":"https://www.cookinglight.com/recipes/pristine-sunny-side-up-eggs"}

Post a image

curl -X POST "http://localhost:8000/api/recipe/recipes/1/upload-image/" -H  "Authorization: Token 4037d08542ee003d9f59dac2b8e7b06f544d5817" -H "Content-type: multipart/form-data" -F "image=@/Users/user/Downloads/sunny-egg.jpeg"
{"id":1,"image":"http://localhost:8000/media/uploads/recipe/be1738f4-5668-47b6-9868-216dfe3f14fd.jpeg"}

Get recipe

curl -X GET "http://localhost:8000/api/recipe/recipes/1/" -H  "accept: application/json" -H  "Authorization: Token 4037d08542ee003d9f59dac2b8e7b06f544d5817"
{"id":1,"title":"Sunny-side-up egg","ingredients":[{"id":1,"name":"egg"}],"tags":[{"id":1,"name":"breakfast"}],"time_minutes":5,"price":"1.00","link":"https://www.cookinglight.com/recipes/pristine-sunny-side-up-eggs"}
A rest api to let user store their recipes, ingredients, tag, and images.
Avatar of the user.
Please login to comment.

Published: Jun 19th 2021
99
6
0

Tools

django
Django
python
Python

Swagger
python
Django-rest-framework

Share