Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.
/ bucketlist Public archive

CP2 @andela Simulations Ninja 🏃 [Flask - a @python Microframework, REST API]

Notifications You must be signed in to change notification settings

NdagiStanley/bucketlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bucket List Service API

Build Status Coverage Status Code Climate Issue Count Code Health

Checkpoint Status

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:

Flask, python, mysql (Image courtesy- codehandbook.org)

Installation

We'll use the terminal here

  1. Clone the repo run: git clone https://github.com/NdagiStanley/bucketlist.git

  2. Create a virtual environment using virtualenv or virtualenvwrapper

  3. In the virtual environment install DEPENDENCIES RUN pip install -r requirements.txt

Task 0

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"
}

Task 1

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

Task 2

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

Task 3

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.

Running

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:

{
  "username": "user1",
  "password": "p@ssw0rd",
  "conf_password": "p@ssw0rd"
}
{
  "username": "user1",
  "password": "p@ssw0rd"
}

This returns a token in this format:

{
  "token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTQ1ODEwNjkyMCwiaWF0IjoxNDU4MTAzMzIwfQ.eyJpZCI6Nn0.irPIrqstGIupCD428dtSOxV8zzwm5IgoCLpTsk-oH5k"
}

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"
}

In the format below:

{
  "title": "Travel"
}

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

Testing

RUN nosetests

RUN coverage run tests.py

For both tests and coverage RUN nosetests --with-coverage


Copyright AD-2016

About

CP2 @andela Simulations Ninja 🏃 [Flask - a @python Microframework, REST API]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages