Coder Social home page Coder Social logo

bucket_api's Introduction

Bucket List API

Build Status Coverage Status BCH compliance Codacy Badge

The api enables you to create/ register a user within the application.

I wrote up a post on medium of how I developed this API, you can find it here

Usage

Starting the application

In order to run the application set the environment variable below.

Windows
set FLASK_APP=run.py

Unix
export FLASK_APP=run.py

Then run the command below to start the application.

flask run

Live Application

This API is hosted here on heroku

API Documentation

The api documentation is hosted as the homepage of the application.

Users

User registration.

Send a POST request to v1/auth/register endpoint with the payload in Json

An example would be

{
  "email": "[email protected]",
  "password": "123456"
}

The email value must be a valid email format and the password must be four characters and above. If the email is invalid or empty and the password is empty or less than four character, the response status will be failed with the message Missing or wrong email format or password is less than four characters and a status code of 202

As shown below:

{
    "message": "Missing or wrong email format or password",
    "status": "failed"
}

If the user already exists then they wont be registered again, the following response will be returned.

{
    "message": "Failed, User already exists, Please sign In",
    "status": "failed"
}

If the request is successful and the user has been registered the response below is returned. With an auth token

{
    "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDM0ODQ5OTYsImlhdCI6MTUwMzM5ODU4Niwic3ViIjo1fQ.GC6IEOohdo_xrz9__UeugIlir0qtJdKbEzBtLgqjt5A",
    "message": "Successfully registered",
    "status": "success"
}

User Login

The user is able to login by send sending a POST request to v1/auth/login with the json payload below.

{
  "email": "[email protected]",
  "password": "123456"
}

If the request is successful the following response is returned:

{
    "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDM0OTIzMzQsImlhdCI6MTUwMzQwNTkyNCwic3ViIjo1fQ.dRDTIP93WNRNv5Q7vCLLHuZfwvH5ze2B_VdRm6qHJbU",
    "message": "Successfully logged In",
    "status": "success"
}

Otherwise if the email is invalid, user with the email does not exist or the password length is incorrect or less than four characters, the following response is returned.

{
    "message": "Missing or wrong email format or password is less than four characters",
    "status": "failed"
}

User Logout

The api also enables a user to logout. The auth/logout endpoint provides this functionality. The POST request to the endpoint must have an Authorization header containing the auth token, otherwise the user wont be logged out.

Example of the Authorization header

Authorization Bearer <token>

If the operation is successful, the response below will be returned.

{
    "message": "Successfully logged out",
    "status": "success"
}

If the token has expired this will be returned.

{
    "message": "Signature expired, Please sign in again",
    "status": "failed"
}

For an invalid token

{
    "message": "Invalid token. Please sign in again",
    "status": "failed"
}

Without an Authorization header

{
    "message": "Provide an authorization header",
    "status": "failed"
}

Buckets

The user is also able to create and get back a list of their buckets.

Create Bucket

Below is an example of a request to create a bucket. name is a required attribute. An auth token must be attached in the Authorization header

{
  "name": "Travel"
}

The following response will be returned

{
    "createdAt": "Wed, 23 Aug 2017 10:14:52 GMT",
    "id": 2,
    "modifiedAt": "Wed, 23 Aug 2017 10:14:52 GMT",
    "name": "Travel",
    "status": "success"
}

Get user`s Buckets

Below is an example of a get request endpoint to get the users buckets. An auth token must be attached in the Authorization header. The results returned are paginated.

v1/bucketlists

Get a user bucket by Id

You can also get a bucket by its id by using the this endpoint and replacing the bucket_id with an existing bucket Id.

v1/bucketlists/<bucket_id>

The following response will be returned.

{
    "bucket": {
        "createdAt": "2017-08-24T19:56:07.942974",
        "id": 3,
        "modifiedAt": "2017-08-24T19:56:07.942974",
        "name": "Travel"
    },
    "status": "success"
}

Edit a bucket

You can also edit the bucket name by sending a PUT request to this endpoint with a Json payload having the name attribute

v1/bucketlists/<bucket_id>

Payload

{
  "name": "Cooking"
}

Delete a Bucket

A bucket can also be deleted by sending a Delete request with the bucket Id as shown below.

v1/bucketlists/<bucket_id>

BucketItems

You can also add, edit, update and delete items in a Bucket.

Get Items from a Bucket

Get all the items contained in the bucket by specifying the Bucket Id. The results returned paginated.

v1/bucketlists/<bucket_id>/items

Get an Item from the Bucket

You can also get an item from the Bucket by specifying the item Id and Bucket Id as shown in the endpoint below.

v1/bucketlists/<bucket_id>/items/<item_id>

Add item to bucket

Send a Json payload with the item name and/or description to this endpoint by specifying the Bucket Id.

v1/bucketlists/<bucket_id>/items

Example Json payload

{
  "name": "biscuits",
  "description": "lorem ispum"
}

Edit an Item in the Bucket

An item can be edited by sending a PUT request with a Json payload with a name and/or description. Specifying the Bucket Id and Item Id as shown in the endpoint below.

v1/bucketlists/<bucket_id>/items/<item_id>

Delete an Item from the Bucket

To delete an item from a Bucket, send a DELETE request specifying a Bucket Id and Item Id as shown below:

v1/bucketlists/<bucket_id>/items/<item_id>

Generating dummy data

You can also generate dummy data to test out the different API endpoints. All you have to do is run this command

python manage.py dummy

A user with an email address of [email protected] and password 123456 is created. And also 100 Buckets and 1000 Bucket Items are created and items linked to the different Buckets.

Running tests

Before running the application tests, update your env variables

export  APP_SETTINGS=app.config.TestingConfig
export DATABASE_URL_TEST=<postgres database url>

Running tests without coverage

You can now run the tests from the terminal

python manage.py test

Running tests with coverage

You can also run tests with coverage by running this command in the terminal

nosetests --with-coverage --cover-package=app

bucket_api's People

Contributors

jokamjohn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.