Skip to content

A Flask RESTful API built with Flask-RESTX that simulates a Pizza Restaurant domain.

License

Notifications You must be signed in to change notification settings

ArshavineRoy/pizza-restaurants-api

Repository files navigation

Pizza Restaurants Flask API

Phase 4 Week 1 : Flask Code Challenge

license python version Flask version Flask-RESTX version Gunicorn version Pytest version

Introduction

This is a Flask API that simulates a Pizza Restaurant domain.

API Image

Features

  • Create a restaurant
  • Get all restaurants
  • Find, update, or delete a restaurant by ID
  • Create a pizza
  • Get all pizzas
  • Find, update, or delete a pizza by ID
  • Create a new RestaurantPizza that is associated with an existing Pizza and Restaurant

Installation

1. Clone the repository

git clone https://github.com/ArshavineRoy/pizza-restaurants-api

2. Navigate to the project's directory

cd pizza-restaurants-api

3. Install required dependencies

pipenv install
  • If pipenv is not already installed, you can do so using pip:

    pip install pipenv

4. Activate the virtual environment

pipenv shell

5. If needed, seed the database with

python3 seed.py

6. Run the Flask server from the root directory

python3 run.py

7. Use an API management tool e.g., Postman / Insomnia to make requests

Usage

  1. POST/restaurants

    Returns JSON data for the created restaurant in the format below:

     [
       {
         "id": 1,
         "name": "Kilimanjaro Jamia",
         "address": "23 Banda Street, Nairobi"
       },
     ]
  2. GET/restaurants

    Returns JSON data for restaurants in the format below:

     [
       {
         "id": 1,
         "name": "Dominion Pizza",
         "address": "Good Italian, Ngong Road, 5th Avenue"
       },
       {
         "id": 2,
         "name": "Pizza Hut",
         "address": "Westgate Mall, Mwanzi Road, Nrb 100"
       }
     ]
  3. GET/restaurants/:id

    Returns JSON data for the requested restaurant in the format below:

      {
       "id": 1,
       "name": "Dominion Pizza",
       "address": "Good Italian, Ngong Road, 5th Avenue",
       "pizzas": [
         {
           "id": 1,
           "name": "Cheese",
           "ingredients": "Dough, Tomato Sauce, Cheese"
         },
         {
           "id": 2,
           "name": "Pepperoni",
           "ingredients": "Dough, Tomato Sauce, Cheese, Pepperoni"
         }
        ]
      }
  4. PATCH/restaurants/:id

    Returns JSON data for the updated restaurant in the format below:

    • For example: PATCH/restaurants/1 to update address from 23 to 25 Banda Street, Nairobi.

      PATCH request:

        [
          {
            "name": "Kilimanjaro Jamia",
            "address": "231 Banda Street, Nairobi"
          },
        ]

      Response:

        [
          {
            "id": 1,
            "name": "Kilimanjaro Jamia",
            "address": "231 Banda Street, Nairobi"
          },
        ]
  5. DELETE /restaurants/:id

    Removes a restaurant from the database along with any RestaurantPizzas that are associated with it and returns an empty dictionary.

  6. POST/pizzas

    Returns JSON data for the created pizza in the format below:

     [
       {
         "id": 1,
         "name": "BBQ chicken",
         "ingredients": "Dough, Cheese, chicken"
       },
     ]
  7. GET /pizzas

    Return JSON data for pizzas in the format below:

    [
       {
         "id": 1,
         "name": "Hawaiian",
         "ingredients": "Dough, Tomato Sauce, Cheese"
       },
       {
         "id": 2,
         "name": "Pepperoni",
         "ingredients": "Dough, Tomato Sauce, Cheese, Pepperoni"
       }
     ]
  8. GET/pizzas/:id

    Returns JSON data for the requested pizza in the format below:

     [
       {
         "id": 1,
         "name": "BBQ chicken",
         "ingredients": "Dough, Cheese, chicken"
       },
     ]
  9. PATCH/pizzas/:id

    Returns JSON data for the updated pizza in the format below:

    • For example: PATCH/pizzas/1 to add tomato sauce ingredient.

      PATCH request:

        [
          {
            "name": "BBQ chicken",
            "ingredients": "Dough, Cheese, chicken, tomato sauce"
          },
        ]

      Response:

        [
          {
            "id": 1,
            "name": "BBQ chicken",
            "ingredients": "Dough, Cheese, chicken, tomato sauce"
          },
        ]
  10. DELETE /pizza/:id

    Removes a pizza from the database along with any Restaurants or RestaurantPizzas that are associated with it and returns an empty dictionary.

  11. POST /restaurant_pizzas

    Creates a new RestaurantPizza that is associated with an existing Pizza and Restaurant and returns JSON data for the pizza in the format below:

    [
      {
        "id": 10,
        "name": "Hawaiian",
        "ingredients": "Dough, Tomato Sauce, Cheese"
      }
    ]

Author & License

Authored by Arshavine Waema.

Licensed under the MIT License - see the LICENSE file for details.

About

A Flask RESTful API built with Flask-RESTX that simulates a Pizza Restaurant domain.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published