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.
pip install -r requirements.txt
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.
- [GET]
/product/<name: string>
- Get product with name:name
- [GET]
/subcategory/<subcategory_id: int>/products
- Get product with within subcategorysubcategory
. Returns first page of the paginated results. - [GET]
/subcategory/<subcategory_id: int>/products?page=<page_no>
- Get product with within subcategorysubcategory
. Returnspage_no
of the paginated results. - [GET]
/category/<category_id: int>/products
- Get product with within categorycategory
. Returns first page of the paginated results. - [GET]
/category/<category_id: int>/products?page=<page_no>
- Get product with within categorycategory
. Returnspage_no
of the paginated results.
-
[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
}
-
[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
}
-
[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
}