boxes-api/api_specification.md

129 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2024-10-06 17:24:39 +00:00
# Boxes API - Frontend Specification
2024-10-05 03:03:50 +00:00
2024-10-06 17:24:39 +00:00
This document outlines the API endpoints for a simple inventory management system called "Boxes".
2024-10-05 03:03:50 +00:00
**Authentication:**
* All endpoints (except `/login`) require a valid JWT token in the `Authorization` header, formatted as `Bearer <token>`.
* To obtain a token, send a POST request to `/login` with the following JSON payload:
2024-10-06 17:24:39 +00:00
2024-10-05 03:03:50 +00:00
```json
{
"username": "your_username",
"password": "your_password"
}
```
2024-10-06 17:24:39 +00:00
2024-10-05 03:03:50 +00:00
* Successful login will return a JSON response with the token:
2024-10-06 17:24:39 +00:00
2024-10-05 03:03:50 +00:00
```json
{
"token": "your_jwt_token"
}
```
**Endpoints:**
**1. Boxes:**
2024-10-06 17:24:39 +00:00
* **GET /boxes:**
* Returns a list of all boxes.
* Response: Array of Box objects
2024-10-05 03:03:50 +00:00
```json
[
{
"id": 1,
"name": "Kitchen"
},
{
"id": 2,
"name": "Bedroom"
}
]
```
2024-10-06 17:24:39 +00:00
* **POST /boxes:**
* Creates a new box.
* Request body: JSON object with the box name
2024-10-05 03:03:50 +00:00
```json
{
"name": "New Box"
}
```
2024-10-06 17:24:39 +00:00
* Response: JSON object with the created box's ID and name
2024-10-05 03:03:50 +00:00
```json
{
"id": 3,
"name": "New Box"
}
```
2024-10-06 17:24:39 +00:00
* **DELETE /boxes/{id}:**
* Deletes the box with the specified ID.
* Response: 204 No Content
2024-10-05 03:03:50 +00:00
**2. Items:**
2024-10-06 17:24:39 +00:00
* **GET /items:**
* Returns a list of all items.
* Response: Array of Item objects
2024-10-05 03:03:50 +00:00
```json
[
{
"id": 1,
"name": "Fork",
"description": "Silverware",
"box_id": 1,
"image_path": "path/to/image.jpg"
},
{
"id": 2,
"name": "Pillow",
"description": "Fluffy",
"box_id": 2,
"image_path": "path/to/another_image.png"
}
]
```
2024-10-06 17:24:39 +00:00
* **POST /items:**
* Creates a new item.
* Request body: JSON object with item details
2024-10-05 03:03:50 +00:00
```json
{
"name": "Spoon",
"description": "For soup",
"box_id": 1,
"image_path": "path/to/spoon_image.jpg"
}
```
2024-10-06 17:24:39 +00:00
* Response: JSON object with the created item's ID and name
2024-10-05 03:03:50 +00:00
```json
{
"id": 3,
"name": "Spoon"
}
```
2024-10-06 17:24:39 +00:00
* **GET /items/{id}:**
* Retrieves the item with the specified ID.
2024-10-05 03:03:50 +00:00
* Response: Item object
2024-10-11 15:40:27 +00:00
* **GET /boxes/{id}/items:**
2024-10-06 17:24:39 +00:00
* Retrieves all items within the box with the specified ID.
2024-10-05 03:03:50 +00:00
* Response: Array of Item objects
2024-10-06 17:24:39 +00:00
* **PUT /items/{id}:**
* Updates the item with the specified ID.
* Request body: JSON object with updated item details
* Response: Updated Item object
* **DELETE /items/{id}:**
* Deletes the item with the specified ID.
* Response: 204 No Content