A Flask Based REST API that enables clients to do the following:
- Register, login and manage their account.
- Create, update, view and delete a category.
- Create, update, view or delete recipes.
Python 2.6 or a later version
Install all package requirements in your python virtual environment.
pip install -r requirements.txt
Rename .env.sample into .env
Activate virtual environment:
$ source .venv/bin/activate
To set up unit testing environment:
$ pip install nose
To execute a test file:
$ source .env
$ nosetests
Note After user login, ensure you specify the generated token in the header:
- In postman header key :
x-access-token
value : - While testing on the browser, key in the
<token>
in Authorize header.
You need to initialize database and tables by running migrations.
flask db init
flask db migrate
flask db upgrade
Start the server which listens at port 5000 by running the following command:
python app.py
The API enables pagination by passing in page and limit as arguments in the request url as shown in the following example:
http://127.0.0.1:5000/api-v0/recipe?page=1&limit=10
The API implements searching based on the name using a GET parameter q as shown below:
http://127.0.0.1:5000/api-v0/recipe?q=example
url | Method | Description | Authentication |
---|---|---|---|
/api-v0/auth/register | POST | Registers new user | FALSE |
/api-v0/auth/login | POST | Handles POST request for /auth/login | TRUE |
/api-v0/category | GET | Get every category of logged in user | TRUE |
/api-v0/category/ | GET | Gets the list of categories | TRUE |
/api-v0/category | POST | Create a new category | TRUE |
/api-v0/category/{category_id} | PUT | Update a category | TRUE |
/api-v0/category/{category_id} | DELETE | Delete category by id | TRUE |
/api-v0/recipe | POST | Creates a recipe | TRUE |
/api-v0/recipe | GET | Gets all recipes | |
/api-v0/recipe/{id} | GET | Gets a single recipe | TRUE |
/api-v0/recipe/{id} | PUT | Updates a single recipe | TRUE |
/api-v0/recipe/{id} | DELETE | Deletes a single recipe | TRUE |