API to the yummy recipes service
After registration, a user should obtain an auth token for use with subsequent requests. The authentication token is passed in the header section of resource requests. The authentication header takes the form:
Authorization: Token <token value>
- User registration
- User token retrieval
- User list retrieval
- Recipe creation
- Recipe list retrieval
- Recipe instruction creation
- Instruction list retrieval
- Recipe ingredient creation
- Ingredient list retrieval
Sample Request: POST http://127.0.0.1:5000/users/
with JSON payload
that looks something like:
{
"first_name": "Emma",
"last_name": "Stone",
"email": "ema@comics.com",
"username": "ema",
"password": "weakpass"
}
Sample Response: {'status': 201}
Request format: POST http://127.0.0.1:5000/login/
with a JSON payload
like:
{
"email": "auth_user@realemail.com",
"password": "weakpass"
}
Sample Response:
{
"token": 6e4daedb5c452d5a3f9e30d332c651ad5a572111
}
Sample request: GET http://127.0.0.1:5000/users/
Sample response:
[
{
"email": "jdoe@anonpersons.com",
"first_name": "Jane",
"id": 1,
"last_name": "Doe",
"username": "jdoe"
},
{
"email": "jsmith@anonmail.com",
"first_name": "John",
"id": 2,
"last_name": "Wayasay",
"username": "jsmith"
},
{
...
}
]
Sample request: GET http://127.0.0.1:5000/users/<user_id>/
Sample response:
{
"email": "jdoe@anonpersons.com",
"first_name": "Jane",
"id": 1,
"last_name": "Doe",
"username": "jdoe"
}
Clients have the ability to search users based on the name.
Sample request GET http://127.0.0.1:5000/search/users?q=<search term>
Sample response:
[
{
"created": "Wed, 25 Oct 2017 18:05:29 GMT",
"email": "lilk@badboyent.com",
"first_name": "Lil",
"id": 3,
"last_name": "Kim",
"modified": null,
"username": "lilk"
}
]
If no matches are found, an empty list/array is returned.
Clients can specify a limit on the number of results that they wish to receive when the request for a list of users, via the limit parameter.
Sample request GET http://127.0.0.1:5000/users/?limit=<limit>
The response will be like the response for a request for a normal
request for the user list except the length of the results arrays will
be limit
Please note that a user may only delete their own user record. Also deleting a user, purges all their recipes, instructions and ingredients.
Sample request: DELETE http://127.0.0.1:5000/users/<user_id>/
Sample response:
{
"status": 204
}
Sample request: POST http://127.0.0.1:5000/recipes/
with a JSON
payload like:
{
"user_id": 1,
"title": "First Recipe",
"description": "This awesome recipe belongs to user with ID 1",
"fulfilled": false
}
Sample Response:
{
"status": 201
}
- Clone this repository
- cd into the project directory
- Create a virtual environment
- Activate the virtual environment
- Run pip install against
requirements.txt
-
Create a database in PostgreSQL for the project with:
$ createdb yummy_recipes
-
Login into the database, via psql for example, and create a yummy recipes user with the SQL statement:
CREATE USER yummy_recipes WITH PASSWORD 'weakpass';
-
Set the owner of the yummy_recipes database to this new user with the SQL statement:
ALTER DATABASE yummy_recipes OWNER TO yummy_recipes;
-
Set up initial state of the database with:
FLASK_DEBUG=3 FLASK_APP=app.py flask db upgrade
- Start the server with
FLASK_DEBUG=3 FLASK_APP=app.py flask run
(Debug level 3 for extra verbosity)
- Issue requests against the server using a tool like curl or postman