To complete this checkpoint you must have completed Modules 5, 6 and 7.
According to Merriam-Webster Dictionary, a Bucket List is a list of things that one has not done before but wants to do before dying. In this exercise you will be required to create an API for an online Bucket List service using Flask. Specifications for the API are shown below. You may use any database you prefer for this assignment.
EndPoint | Functionality |
---|---|
POST /auth/login |
Logs a user in |
POST /auth/register |
Register a user |
POST /bucketlists/ |
Logs a user in |
GET /bucketlists/ |
List all the created bucket lists |
GET /bucketlists/<id> |
Get single bucket list |
PUT /bucketlists/<id> |
Update this bucket list |
DELETE /bucketlists/<id> |
Delete this single bucket list |
POST /bucketlists/<id>/items/ |
Create a new item in bucket list |
PUT /bucketlists/<id>/items/<item_id> |
Update a bucket list item |
DELETE /bucketlists/<id>/items/<item_id> |
Delete an item in a bucket list |
Best Practices for a pragmatic RESTful API
For this task you will be creating the models for the data which your application will be manipulating. This should be done using SQLAlchemy.
For this task you will be creating scripts for handling migration of data when the data model changes. The script should contain the following tasks.
- Create migrations
- Apply migrations
- Manually Create databases
- Manually Drop databases
For this task you are required to create a flexible way for storing the application configurations. For this task, think about the different environments your application will be deployed to i.e Testing, Development and Production.
In this task you are required to create the API endpoints described above using any of Flask, Flask-RESTful or Flask-RESTless as primary framework. Refer to the documentation on HTTP, APIs and Webservices for information on considerations and best practices.
The prefered JSON response for a single bucket list is shown below.
{ id: 1, name: “BucketList1”, items: [ { id: 1, name: “I need to do X”, date_created: “2015-08-12 11:57:23”, date_modified: “2015-08-12 11:57:23”, done: False } ] date_created: “2015-08-12 11:57:23”, date_modified: “2015-08-12 11:57:23” created_by: “1113456” }
Ensure that your API is versioned as v1. See the material referenced above for more details on this.
For this task, you are required to implement Token Based Authentication for the API such that some methods are not accessible via unauthenticated users. Access control mapping is listed below.
EndPoint | Public Access |
---|---|
POST /auth/login |
TRUE |
POST /auth/register |
TRUE |
POST /bucketlists/ |
FALSE |
GET /bucketlists/ |
FALSE |
GET /bucketlists/<id> |
FALSE |
PUT /bucketlists/<id> |
FALSE |
DELETE /bucketlists/<id> |
FALSE |
POST /bucketlists/<id>/items/ |
FALSE |
PUT /bucketlists/<id>/items/<item_id> |
FALSE |
DELETE /bucketlists/<id>/items/<item_id> |
FALSE |
For this task, you are required to implement pagination on your API such that users can specify the number of results they would like to have via a GET parameter limit
. The default number of results is 20 and the maximum number of results is 100.
GET http://localhost:5555/bucketlists?limit=20
20 bucket list records belonging to the logged in user.
For this task, you are required to implement searching for bucket lists based on the name using a GET
parameter q
. The result set should also be paginated.
GET http://localhost:5555/bucketlists?q=bucket1
Bucket lists with the string “bucket1” in their name.
- Stretch your API to see how it performs for multiple requests using Apache AB.
- Build a mobile front-end for your application using Ionic.
- Read more about best practices for API design.
-
Clone Repo:
$ git clone git@github.com:asce1062/CP2A-BucketList-Application-API.git
-
Navigate to local directory.
$ cd CP2A-BucketList-Application-API
-
Install virtualenv via pip:
$ pip install virtualenv
-
Install virtualenvwrapper via pip:
$ pip install virtualenvwrapper $ export WORKON_HOME=$HOME/.virtualenvs $ export PROJECT_HOME=$HOME/Devel $ source /usr/local/bin/virtualenvwrapper.sh $ source ~/.bashrc $ mkvirtualenv bucket $ workon bucket
-
Install Mac OS X Using Homebrew:
$ brew install autoenv $ echo "source $(brew --prefix autoenv)/activate.sh" >> ~/.zshrc
-
Run the menu script
$ ./menu
-
Select options from the menu from 1 to 6. (Ohers are optional)
-
[POST] http://127.0.0.1:5000/api/v1.0/auth/register/ :args: 'username': 'asce1062' 'first_name': 'Alex' 'last_name': 'Immer' 'email': 'tnkratos@gmail.com' 'password': 'onepiece'
-
[POST] http://127.0.0.1:5000/api/v1.0/auth/login/ :args: 'email': 'kratostn@gmail.com', 'password': 'onepiece'
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime'
-
[Get] http://127.0.0.1:5000/api/v1.0/bucketlists/
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [Get] http://127.0.0.1:5000/api/v1.0/bucketlists/1/
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [PUT] http://127.0.0.1:5000/api/v1.0/bucketlists/1/
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [DELETE] http://127.0.0.1:5000/api/v1.0/bucketlists/?limit=1
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [Get] http://127.0.0.1:5000/api/v1.0/bucketlists/?q=Watch Anime
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [Get] http://127.0.0.1:5000/api/v1.0/bucketlists/?limit=1
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [POST] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/ :args: 'item_name': 'One Piece' 'done': 'False'
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [GET] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [GET] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/1
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [POST] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/ :args: 'item_name': 'One Piece' 'done': 'False' [PUT] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/1 :args: 'item_name': 'One Piece' 'done': 'True'
-
[POST] http://127.0.0.1:5000/api/v1.0/bucketlists/ :args: 'bucketlist_name': 'Watch Anime' [POST] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/ :args: 'item_name': 'One Piece' 'done': 'False' [DELETE] http://127.0.0.1:5000/api/v1.0/bucketlists/1/items/1