Skip to content

RESTful API for an ecommerce website with categories, subcategories and products using flask.

Notifications You must be signed in to change notification settings

piyush-jaiswal/ecommerce-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ecommerce REST API

RESTful HTTP API using Python Flask that allows users to manage their ecommerce platform.

Ability to create, read, update, and delete products, categories and subcategories. A category can have multiple subcategories and a subcategory can belong to multiple categories. Products can belong to multiple categories and subcategories.

Fetching a product fetches the details of categories and subcategories it belongs to. Provides the ability to search for products by name, category and subcategories.

Paginates result when products are fetched by categories or subcategories.

Requirements

pip install -r requirements.txt

Usage

Start the server:

python app.py (Starts the server on 127.0.0.1:5000)

This project is preloaded with a dummy sqlite database located in the instance directory. To start from a scratch db, delete the instance directory and start the server.

To test the API using Postman, install postman agent in your OS and call the API using Postman.

Endpoints

Fetch products using name, category, subcategory

  • [GET] /product/<name: string> - Get product with name: name

  • [GET] /subcategory/<subcategory_id: int>/products - Get product with within subcategory subcategory. Returns first page of the paginated results.

  • [GET] /subcategory/<subcategory_id: int>/products?page=<page_no> - Get product with within subcategory subcategory. Returns page_no of the paginated results.

  • [GET] /category/<category_id: int>/products - Get product with within category category. Returns first page of the paginated results.

  • [GET] /category/<category_id: int>/products?page=<page_no> - Get product with within category category. Returns page_no of the paginated results.



Category

  • [GET] /categories - Get all categories

  • [GET] /category/(int: category_id) - Get category with category_id

  • [DELETE] /category/(int: category_id) - Delete category with category_id

  • [POST] /category/create - Create a new category

{
  "name": "name",
  "subcategories": [<subcategory ids>] //optional
}
  • [PUT] /category/(int: category_id)/update - Update category with category_id
{
  "name": "name",
  "subcategories": [<subcategory ids>] //optional
}



Subcategory

  • [GET] /subcategories - Get all subcategories

  • [GET] /subcategory/(int: subcategory_id) - Get subcategory with subcategory_id

  • [DELETE] /subcategory/(int: subcategory_id) - Delete subcategory with subcategory_id

  • [POST] /subcategory/create - Create a new subcategory

{
  "name": "name",
  "categories": [(category ids)] //optional
  "products": [<subcategory ids>] // optional
}
  • [PUT] /subcategory/(int: subcategory_id)/update - Update subcategory with subcategory_id
{
  "name": "name",
  "categories": [<category ids>] //optional
  "products": [<subcategory ids>] // optional
}



Product

  • [GET] /products - Get all products

  • [GET] /product/(int: product_id) - Get product with product_id

  • [DELETE] /product/(int: product_id) - Delete product with product_id

  • [POST] /product/create - Create a new product

{
  "name": "name",
  "description": "description",
  "subcategories": [<subcategory ids>] //optional
}
  • [PUT] /product/(int: product_id)/update - Update product with product_id
{
  "name": "name",
  "description": "description",
  "subcategories": [<subcategory ids>] //optional
}