This API allows you to manage the inventory and suppliers of an online store. You can perform CRUD operations on inventory items and suppliers, as well as view relationships between them.
-
Clone the Repository:
git clone https://github.com/LexxLuey/drf-api-template.git cd drf-api-template
-
Create and Activate Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.dev.txt
-
Apply Migrations:
python manage.py migrate
-
Run the Development Server:
python manage.py runserver
Please visit the swagger docs for a more detailed documentation of all endpoints.
-
List Items
- URL:
/api/inventory/
- Method:
GET
- Description: Retrieves a list of all inventory items.
- Response: JSON array of items
- URL:
-
Create Item
- URL:
/api/inventory/
- Method:
POST
- Description: Creates a new inventory item.
- Request Body:
{ "name": "string", "description": "string", "price": "float", "date_added": "YYYY-MM-DD", "suppliers": [{ "name": "string", "contact_info": "string" }], "suppliers_id": [1, 2] }
- Response: JSON object of the created item
- URL:
-
Retrieve Item
- URL:
/api/inventory/{id}/
- Method:
GET
- Description: Retrieves details of a specific inventory item.
- Response: JSON object of the item
- URL:
-
Update Item
- URL:
/api/inventory/{id}/
- Method:
PUT
- Description: Updates an inventory item.
- Request Body:
{ "name": "string", "description": "string", "price": "float", "date_added": "YYYY-MM-DD", "suppliers": [{ "name": "string", "contact_info": "string" }], "suppliers_id": [1, 2] }
- Response: JSON object of the updated item
- URL:
-
Delete Item
- URL:
/api/inventory/{id}/
- Method:
DELETE
- Description: Deletes an inventory item.
- Response:
204 No Content
- URL:
-
Item Suppliers
- URL:
/api/inventory/{id}/suppliers/
- Method:
GET
- Description: Retrieves suppliers for a specific inventory item.
- Response: JSON array of suppliers
- URL:
-
List Suppliers
- URL:
/api/suppliers/
- Method:
GET
- Description: Retrieves a list of all suppliers.
- Response: JSON array of suppliers
- URL:
-
Create Supplier
- URL:
/api/suppliers/
- Method:
POST
- Description: Creates a new supplier.
- Request Body:
{ "name": "string", "contact_info": "string" }
- Response: JSON object of the created supplier
- URL:
-
Retrieve Supplier
- URL:
/api/suppliers/{id}/
- Method:
GET
- Description: Retrieves details of a specific supplier.
- Response: JSON object of the supplier
- URL:
-
Update Supplier
- URL:
/api/suppliers/{id}/
- Method:
PUT
- Description: Updates a supplier.
- Request Body:
{ "name": "string", "contact_info": "string" }
- Response: JSON object of the updated supplier
- URL:
-
Delete Supplier
- URL:
/api/suppliers/{id}/
- Method:
DELETE
- Description: Deletes a supplier.
- Response:
204 No Content
- URL:
-
Supplier Items
- URL:
/api/suppliers/{id}/items/
- Method:
GET
- Description: Retrieves items supplied by a specific supplier.
- Response: JSON array of items
- URL:
To create multiple suppliers, use the management command:
python manage.py create_suppliers <num_suppliers>
Example:
python manage.py create_suppliers 20
To create multiple items and randomly attach them to suppliers, use the management command:
python manage.py create_items <num_items>
Example:
python manage.py create_items 50
To run the tests, use the following commands:
python manage.py test
This documentation provides the basic setup and usage instructions for the API. For further details and advanced usage, please refer to the source code, comments within the codebase and the swagger docs.