I have a good experience with Android Frontend REST API calls, but I am very new to Backend and learning Django Framework so I need help for designing the below API endpoints.
For better understanding I have uploaded a video over here https://youtu.be/z87Hz1uHrYY.
This is the solution which I was thinking of doing,
) HTTP-Method: POST
EndPoint URL: /recipe/
Request Params: {"name":"Pizza"} "image": pizza.png
Response Params: {"id":"123xyz"} // unique id
) HTTP-Method PATCH
EndPoint URL: /recipe/123xyz/
Request Params: {"serving":2, "difficulty": "m", "prep_time": 80}
Response Params: {"id":"123xyz", "serving":2, "difficulty": "m", "prep_time": 80}
) HTTP-Method: PATCH
EndPoint URL: /recipe/123xyz/ingredients/
Request Params: [{"ingredient":”rice”, “amount”: “1/2”, “unit”: “g”},{"ingredient":”water”, “amount”: “1/2”, “unit”: “ml”}]
Response Params: {"id":"123xyz", "serving":2, "difficulty": "m", "prep_time": 80, “ingredients”: [{"ingredient":”rice”, “amount”: “1/2”, “unit”: “g”, “index”:1},{"ingredient":”water”, “amount”: “1/2”, “unit”: “ml”, “index”:2}] }
) HTTP-Method: PATCH
EndPoint URL: /recipe/123xyz/steps/
Request Params: [{"description":”abc”, “image”: “s3//step1.png”, "index": 1},{"description":”xyz”, “video”: “s3//step2.mp4”, "index": 2}]
Response Params: {"id":"123xyz", "serving":2, "difficulty": "m", "prep_time": 80, “ingredients”:[{"ingredient":”rice”, “amount”: “1/2”, “unit”: “g”, “index”:1},{"ingredient":”water”, “amount”: “1/2”, “unit”: “ml”, “index”:2}],
"steps":[{"description":”abc”, “image”: “s3//step1.png”, "index": 1},{"description":”xyz”, “video”: “s3//step2.mp4”, "index": 2}]}
These are the API breakdowns that I can think of with the questions below.
) How to handle reordering of ingredients and steps?
) When to upload image or video, first upload file and get the url of s3 and then make /recipe/123xyz/steps/ api call. Or upload file along with /recipe/123xyz/steps/ API call?
Feel free to correct me if I am wrong and suggest a better API design approach for this use case.