Be able to CRUD bucketlists
BLiSA is a simple REST API allowing users to CREATE bucketlists (things you want to do before you expire) and items in them. Then they are able to READ, UPDATE and DELETE them.
It's implementing:
(Image courtesy- codehandbook.org)
We'll use the terminal here
-
Clone the repo run:
git clone https://github.com/NdagiStanley/bucketlist.git
-
Create a virtual environment using virtualenv or virtualenvwrapper
-
In the virtual environment install DEPENDENCIES RUN
pip install -r requirements.txt
Implement the API in this structure:
{
"id": 1,
"name": "BucketList1",
"items": [
{
"id": 1,
"title": "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"
}
Implement Token Based Authentication
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 |
The responses all belong to the logged in user
Implement Pagination on the API
Adding ?limit=20
to the bucketlists endpoint to specify the number of results returned.
The limit is edittable via the url but set the default as 20 and maximum as 100
Pagination is also implemented.
The following will return the second page after limiting results to the default 20 per page
Here is an example of pagination with custom limit. The results are 10 per page and we have requested the second page
Implement Searching by name
Adding ?q=bucket1
to the bucketlists endpoint to specify characteristics of results returned.
In this case expected results are Bucket lists with the string "bucket1" in their name
?q=b
will return Bucket lists with the string "b" in their name including those with the string "b", "bu", "buc", "buck" and so on.
RUN python api/manage.py start
to create the db and tables to be used
RUN python api/manage.py runserver
and go the pages at:
-
http://localhost:5000/ index page (GET)
-
http://localhost:5000/auth/register/ signup page (POST)
{
"username": "user1",
"password": "p@ssw0rd",
"conf_password": "p@ssw0rd"
}
- http://localhost:5000/auth/login/ login page (POST)
{
"username": "user1",
"password": "p@ssw0rd"
}
This returns a token in this format:
{
"token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ1ODEwNjkyMCwiaWF0IjoxNDU4MTAzMzIwfQ.eyJpZCI6Nn0.irPIrqstGIupCD428dtSOxV8zzwm5IgoCLpTsk-oH5k"
}
- http://localhost:5000/bucketlists/ endpoints (GET, POST)
The token will be used in all subsequent requests. Otherwise the requests will be unauthorised.
In Postman enter the token in the header like this: (NB: The Content-Type is necessary in GET and PUT methods)
In POST the body should be in this format:
{
"name": "Travel"
}
- http://localhost:5000/bucketlists/1 endpoints (GET, PUT, DELETE) the body for PUT here is same as the above body 👆
- http://localhost:5000/bucketlists/1/items/ endpoints (POST)
In the format below:
{
"title": "Travel"
}
- http://localhost:5000/bucketlists/1/items/1 endpoints (PUT, DELETE)
In PUT the body should be in this format:
{
"title": "Travel to Mombasa",
"done": true
}
or either:
{
"title": "Travel to Mombasa"
}
{
"done": true
}
RUN python api/manage.py exit
to exit from the API
RUN nosetests
RUN coverage run tests.py
For both tests and coverage
RUN nosetests --with-coverage
Copyright AD-2016