Skip to content

matixezor/fresh-gelato-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fresh Gelato API

API created with Django Rest Framework with JWT authentication

Table of contents

  1. Introduction
  2. Installation
  3. API Endpoints
  4. Tests

Introduction

This simple API was created to serve gelato recipes. You can add recipes and ingredients. The authentication is done via JWT token. There is an endpoint to allow customers to contact the company via mail. I wanted to learn DRF and this is the result. There's still some room to improve it and it will be done soon.

Installation

Use $ pip install -r requirements.txt to install all the required packages.
Use $ python manage.py makemigrations and $ python manage.py migrate to setup your database.
Use $ python manage.py createsuper to create your admin account.
Use $ python manage.py runserver to run the server locally.

API endpoints

To attach token to the request, add a header: Authorization: JWT {token}

  • api/token-auth/
    • Methods:
      • POST
    • Authorization:
      • POST: Allow any
    • Description: Send login credentials to receive token and user info
    • Query:
      * { "username": string, "password": string } 
    • Response: Code: 200, Json:
      {
      "token": string,
      "user": {
          "username": string,
          "first_name": string,
          "last_name": string,
          "email": string
         }
      }
  • api/recipes/
    • Methods:
      • GET
      • POST
    • Authorization:
      • GET: Authenticated only
      • POST: Staff only
    • Description: Get all recipes or Create new recipe
    • Query:
    {
    "name": string,
    "image": string, #not required
    "base_amount": int,
    "ingredients": [
       {
         "name": string,
         "price": int,
         "percentage": int
       },
       {
         "name": string,
         "price": int,
         "percentage": int
       },
       ...
      ]
     }
    • Response:
      • POST Code: 201 or 400 if Bad Request
      • If unauthorized: 401
      • GET Code: 200, Json:
      [{
              "id": int,
              "name": string,
              "image": null or string
          }, {
              "id": int,
              "name": string,
              "image": null or string
          },
          ...
      }]
  • /api/recipes/{id}
    • Methods:
      • GET
    • Authorization:
      • GET: Authenticated only
    • Description: Get specified recipe
    • Response:
      • If unauthorized: 401
      • GET Code: 200 or 404 if not found, Json:
    {
        "id": int,
        "name": string,
        "base_amount": int,
        "total_price": float,
        "image": string or null,
        "ingredient_count": int,
        "ingredients": [{
                "name": string,
                "amount": int,
                "price": float,
                "cost": float,
                "percentage": float
            },
            ...
        ],
    }
  • /api/send-email/
    • Methods: POST
    • Authorization:
      • POST: Allow any
    • Description: Post email to contact the company
    • Query:
    {
        "sender_name": string,
        "sender_mail": string,
        "content": string
    }
    • Response:
      • POST Code: 201 or 400 if bad request
  • /api/user/
    • Methods:
      • GET
      • POST
    • Authorization:
      • GET: Authenticated only
      • POST: Allow any
    • Description: Get authenticated user info or Create new user
    • Query:
    {
      "username": string,
      "password": string,
      "first_name": string,	#not required
      "last_name": string,	#not required
      "email": string	#not required
    }
    • Response:
      • POST Code: 201 or 400 if bad request
      • If unauthorized: 401
      • GET Code: 200, Json:
    {
        "username": string,
        "first_name": string,
        "last_name": string,
        "email": string
    }

Tests

There's some basic unit tests.
To run them use: $ python manage.py test

About

Fresh Gelato API written using django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages