Simple CRUD API for a local fruit business.
Every endpoint will respond with required HTTP status codes along side with the required body.
For the hosted onrender api, API_URI=https://sagarmatha-fruits-api.onrender.com/api/v1/
Endpoint:
Method: POST
Type: RAW/JSON
URL: {{API_URI}}/auth/login/admin
Body:
{
"email": "[email protected]",
"password": "test1234"
}
Response:
{
"message": "Login successful",
"token": "signed_jwt_token"
}
The authorization header is required when performing admin related tasks. In case of our api a client should include the token in header when interacting with the endpoints of:
- Create fruit details.
- Update fruit details.
- Delete fruit details.
Key | Value | Description |
---|---|---|
Authorization | Bearer signed_jwt_token | Token obtained from response while logging in. |
You can pass in page and limit as query for pagination, the default values are as"
page=1
and limit=10
.
Endpoint:
Method: GET
Type:
URL: {{API_URI}}/fruits?page=1&limit=5
Response:
{
"message": "All fruits fetched successfully",
"data": [
{
"_id": "fruit_id",
"name": "apple",
"price": 69,
"imageUrl": "https://res.cloudinary.com/dra4rqms4/image/upload/v1704892600/Fruits/dcmkuatx5uudwbcwayhu.jpg",
"__v": 0
}
]
}
Endpoint:
Method: GET
Type:
URL: {{API_URI}}/fruits/fruit_id
Response:
{
"message": "Fruit fetched successfully",
"data": {
"_id": "fruit_id",
"name": "mango",
"price": 69,
"imageUrl": "https://res.cloudinary.com/dra4rqms4/image/upload/v1704896380/Fruits/kmnamq0uwziuvbetkwde.jpg",
"__v": 0
}
}
Endpoint:
Method: POST
Type: FORMDATA
URL: {{API_URI}}/fruits/
Body:
Key | Value | Description |
---|---|---|
name | apple | |
price | 349.9 | |
image | apple.jpeg | |
unit | /kg |
Response:
{
"message": "Fruit created successfully",
"data": {
"name": "apple",
"price": 349.9,
"imageUrl": "https://res.cloudinary.com/dra4rqms4/image/upload/v1704892600/Fruits/dcmkuatx5uudwbcwayhu.jpg",
"unit": "/kg",
"_id": "fruit_id",
"__v": 0
}
}
Endpoint:
Method: PUT
Type: FORMDATA
URL: {{API_URI}}/fruits/fruit_id
Body:
Key | Value | Description |
---|---|---|
name | mango | |
price | 69 |
Response:
{
"message": "Fruit updated successfully",
"data": {
"_id": fruit_id,
"name": "mango",
"price": 69,
"imageUrl": "https://res.cloudinary.com/dra4rqms4/image/upload/v1704896380/Fruits/kmnamq0uwziuvbetkwde.jpg",
"__v": 0
}
}
Endpoint:
Method: DELETE
Type:
URL: {{API_URI}}/fruits/fruit_id
Response:
{
"message": "Fruit deleted successfully",
"data": {
"_id": "fruit_id",
"name": "mango",
"price": 69,
"imageUrl": "https://res.cloudinary.com/dra4rqms4/image/upload/v1704896380/Fruits/kmnamq0uwziuvbetkwde.jpg",
"__v": 0
}
}
Generated at 2024-01-10 20:42:21 by docgen