API Reference
Request and Response Examples for Next-DRF API Endpoints
This page provides sample API calls for the Next-DRF backend, covering various scenarios such as user registration, item management, and order processing. These examples demonstrate how to make requests and what to expect in responses to better understand how the API endpoints work.
1. User Management Examples
1.1 User Registration
- Endpoint:
/api/users/register/
- Method:
POST
- Request Example:
{ "username": "john_doe", "email": "john.doe@example.com", "password": "securepassword123" }
- Response Example (Success -
201 Created
):{ "id": 1, "username": "john_doe", "email": "john.doe@example.com" }
1.2 User Login
- Endpoint:
/api/users/login/
- Method:
POST
- Request Example:
{ "username": "john_doe", "password": "securepassword123" }
- Response Example (Success -
200 OK
):{ "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...", "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." }
1.3 User Profile
- Endpoint:
/api/users/profile/
- Method:
GET
- Headers:
Authorization
:Bearer <access_token>
- Response Example (Success -
200 OK
):{ "id": 1, "username": "john_doe", "email": "john.doe@example.com" }
1.4 Password Reset
- Endpoint:
/api/users/reset-password/
- Method:
POST
- Request Example:
{ "email": "john.doe@example.com" }
- Response Example (Success -
200 OK
):{ "message": "Password reset link sent to the provided email." }
2. Item Management Examples
2.1 Get All Items
- Endpoint:
/api/items/
- Method:
GET
- Response Example (Success -
200 OK
):[ { "id": 1, "name": "Item A", "description": "Description for Item A", "price": 25.50 }, { "id": 2, "name": "Item B", "description": "Description for Item B", "price": 40.00 } ]
2.2 Create a New Item
- Endpoint:
/api/items/
- Method:
POST
- Headers:
Authorization
:Bearer <access_token>
(Admin privileges required)
- Request Example:
{ "name": "Item C", "description": "Description for Item C", "price": 30.00 }
- Response Example (Success -
201 Created
):{ "id": 3, "name": "Item C", "description": "Description for Item C", "price": 30.00 }
3. Order Management Examples
3.1 Create Order
- Endpoint:
/api/orders/
- Method:
POST
- Headers:
Authorization
:Bearer <access_token>
- Request Example:
{ "item_ids": [1, 2], "quantity": 2 }
- Response Example (Success -
201 Created
):{ "id": 101, "user": "john_doe", "items": [ { "id": 1, "name": "Item A", "quantity": 2 }, { "id": 2, "name": "Item B", "quantity": 2 } ], "total_price": 131.00, "status": "pending" }
3.2 Get Order Details
- Endpoint:
/api/orders/{id}/
- Method:
GET
- Headers:
Authorization
:Bearer <access_token>
- Path Parameter:
id
: The ID of the order.
- Response Example (Success -
200 OK
):{ "id": 101, "user": "john_doe", "items": [ { "id": 1, "name": "Item A", "quantity": 2 }, { "id": 2, "name": "Item B", "quantity": 2 } ], "total_price": 131.00, "status": "pending" }
4. Authentication Examples
4.1 Token Refresh
- Endpoint:
/api/token/refresh/
- Method:
POST
- Request Example:
{ "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." }
- Response Example (Success -
200 OK
):{ "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." }
4.2 Token Verification
- Endpoint:
/api/token/verify/
- Method:
POST
- Request Example:
{ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." }
- Response Example (Success -
200 OK
):{ "message": "Token is valid." }
Summary
These request and response examples provide a clear understanding of how to interact with the Next-DRF API endpoints. By following these samples, you can make effective use of the available endpoints for tasks such as user management, item creation, and order processing, ensuring smooth integration between the frontend and backend.