- Git Commit Style Guide
- PEP8 with exceptions:
- Line length of 120 characters tops
- Required trailing comma
- The test section from Django REST in Style
I never needed/wanted to build a bare Python server before this task. Is quite interesting to see what the Frameworks that I often use do underneath.
That said, I want to be completely honest regarding my approaches (that you can check in commits messages/code) and knowledge sources.
Some of what's implemented in the request handler came from here.
Note: Whenever you run this command, the script for database schema creation is run for your convenience (of course, it wouldn't work like this in production).
docker-compose up
If you don't want to bind the process to the current terminal, run the following:
docker-compose up -d
docker-compose run --rm server pytest
docker-compose run --rm server python scripts/create_schema.py
docker-compose run --rm server python scripts/load_mock_data.py
Note: These cURL commands work after loading the mock data
curl -X GET http://localhost:8080/recipes/ # Retrieve recipe list
curl -X GET http://localhost:8080/recipes/1/ # Retrieve a recipe for the specified ID
curl -X POST \
http://localhost:8080/recipes/ \
-H 'Authorization: 1' \
-H 'Content-Type: application/json' \
-d '{"name": "A cool recipe", "difficulty": 1, "vegetarian": false, "preparation_time": 15}' # Create a recipe
curl -X PUT \
http://localhost:8080/recipes/1/ \
-H 'Authorization: 1' \
-H 'Content-Type: application/json' \
-d '{"name": "One fine recipe", "difficulty": 2, "vegetarian": true, "preparation_time": 14}' # Update a recipe with PUT
curl -X PATCH \
http://localhost:8080/recipes/1/ \
-H 'Authorization: 1' \
-H 'Content-Type: application/json' \
-d '{"name": "One fine recipe", "difficulty": 2, "vegetarian": false, "preparation_time": 13}' # Update a recipe with PATCH
curl -X DELETE http://localhost:8080/recipes/1/ -H 'Authorization: 1' # Delete a recipe
curl -X POST http://localhost:8080/recipes/1/rating/ -H 'Content-Type: application/json' -d '{"value": 2}' # Create a rating for a recipe