API Reference
Backend API Endpoints Overview in Next-DRF
In the Next-DRF framework, the Django Rest Framework (DRF) backend provides a set of RESTful API endpoints that serve as the backbone for the application's data exchange between the frontend and backend. Below is an overview of the available API endpoints and their purpose, helping you understand the structure and functionality of the backend.
1. User Management Endpoints
1.1 User Registration
- Endpoint:
/api/users/register/
- Method:
POST
- Description: Allows new users to register by providing basic details like username, email, and password.
- Request Body:
{ "username": "string", "email": "string", "password": "string" }
1.2 User Login
- Endpoint:
/api/users/login/
- Method:
POST
- Description: Authenticates the user and returns a JSON Web Token (JWT) for subsequent requests.
- Request Body:
{ "username": "string", "password": "string" }
1.3 User Profile
- Endpoint:
/api/users/profile/
- Method:
GET
- Description: Retrieves the authenticated user’s profile details.
- Authentication: Requires JWT token.
1.4 Password Reset
- Endpoint:
/api/users/reset-password/
- Method:
POST
- Description: Allows users to reset their password by providing their registered email.
2. Authentication Endpoints
2.1 Token Refresh
- Endpoint:
/api/token/refresh/
- Method:
POST
- Description: Refreshes the JWT token for an authenticated session.
- Request Body:
{ "refresh": "string" }
2.2 Token Verify
- Endpoint:
/api/token/verify/
- Method:
POST
- Description: Verifies the validity of a given JWT token.
- Request Body:
{ "token": "string" }
3. CRUD Endpoints for Resources
3.1 Items List and Detail
- Endpoint:
/api/items/
- Method:
GET
,POST
- Description:
GET
: Retrieves a list of all items available.POST
: Creates a new item (requires admin privileges).
- Authentication: Requires JWT token for creating new items.
3.2 Item Detail
- Endpoint:
/api/items/{id}/
- Method:
GET
,PUT
,DELETE
- Description:
GET
: Retrieves details of a specific item by ID.PUT
: Updates an existing item (requires admin privileges).DELETE
: Deletes an item by ID (requires admin privileges).
- Path Parameters:
id
: The ID of the item.
3.3 Search Items
- Endpoint:
/api/items/search/
- Method:
GET
- Description: Searches items based on query parameters such as name or category.
- Query Parameters:
name
: Filter by item name.category
: Filter by category.
4. Category Management Endpoints
4.1 Categories List
- Endpoint:
/api/categories/
- Method:
GET
,POST
- Description:
GET
: Retrieves a list of all categories.POST
: Creates a new category (requires admin privileges).
4.2 Category Detail
- Endpoint:
/api/categories/{id}/
- Method:
GET
,PUT
,DELETE
- Description:
GET
: Retrieves details of a specific category.PUT
: Updates a category (requires admin privileges).DELETE
: Deletes a category (requires admin privileges).
5. Order Management Endpoints
5.1 Create Order
- Endpoint:
/api/orders/
- Method:
POST
- Description: Creates a new order for an authenticated user.
- Authentication: Requires JWT token.
- Request Body:
{ "item_ids": [ "integer", "integer" ], "quantity": "integer" }
5.2 List Orders
- Endpoint:
/api/orders/
- Method:
GET
- Description: Retrieves all orders placed by the authenticated user.
- Authentication: Requires JWT token.
5.3 Order Detail
- Endpoint:
/api/orders/{id}/
- Method:
GET
- Description: Retrieves the details of a specific order by ID.
- Authentication: Requires JWT token.
6. Admin Endpoints
6.1 Dashboard Metrics
- Endpoint:
/api/admin/metrics/
- Method:
GET
- Description: Provides various metrics for the admin dashboard, such as total users, sales, and items.
- Authentication: Requires admin privileges.
Summary
The Next-DRF framework provides a variety of API endpoints to manage different aspects of the application, from user management and authentication to item, category, and order management. Understanding these endpoints is crucial for effectively integrating the backend with the frontend and ensuring a smooth user experience.
These endpoints form the backbone of the interaction between the frontend and backend, allowing secure and efficient data exchanges for building a full-stack application.