Complete API reference for Alpha Tower Sales System
- Overview
- Authentication
- Base URL
- Status Codes
- Error Handling
- Endpoints
- Request Examples
- Response Examples
The Alpha Tower Sales System API is a RESTful API that provides endpoints for managing users, products, and authentication. All API responses are in JSON format.
The API uses JWT (JSON Web Token) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Default expiration: 24 hours
- Configurable via JWT_EXPIRES_IN environment variable
http://localhost:8080
| Code | Description |
|---|---|
| 200 | OK - Request successful |
| 201 | Created - Resource created successfully |
| 400 | Bad Request - Invalid request data |
| 401 | Unauthorized - Authentication required |
| 404 | Not Found - Resource not found |
| 500 | Internal Server Error - Server error |
All errors follow a consistent format:
{
"status": "error",
"message": "Error description"
}JWT Token is missing.- No authorization header providedInvalid JWT Token.- Token is invalid or expiredEmail address already used.- Email already exists during registrationIncorrect email/password combination.- Invalid login credentials
Create a new session and receive a JWT token.
POST /sessionsRequest Body:
{
"email": "user@example.com",
"password": "password123"
}Response (200 OK):
{
"user": {
"id": "uuid-string",
"name": "John Doe",
"email": "user@example.com",
"avatar": "avatar-filename.jpg",
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
},
"token": "jwt-token-string"
}Validation Rules:
email: Required, must be a valid email formatpassword: Required
Retrieve a list of all users (authenticated route).
GET /usersHeaders:
Authorization: Bearer <jwt-token>
Response (200 OK):
[
{
"id": "uuid-string",
"name": "John Doe",
"email": "john@example.com",
"avatar": "avatar-filename.jpg",
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}
]Retrieve a specific user by their ID (authenticated route).
GET /users/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): User ID
Response (200 OK):
{
"id": "uuid-string",
"name": "John Doe",
"email": "john@example.com",
"avatar": "avatar-filename.jpg",
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}Register a new user account.
POST /usersRequest Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}Response (201 Created):
{
"id": "uuid-string",
"name": "John Doe",
"email": "john@example.com",
"avatar": null,
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}Validation Rules:
name: Required stringemail: Required, must be a valid email format, must be uniquepassword: Required string
Update an existing user (authenticated route).
PUT /users/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): User ID
Request Body:
{
"name": "John Updated",
"email": "john.updated@example.com",
"password": "newpassword123"
}Response (200 OK):
{
"id": "uuid-string",
"name": "John Updated",
"email": "john.updated@example.com",
"avatar": "avatar-filename.jpg",
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T12:00:00.000Z"
}Validation Rules:
name: Required stringemail: Required, must be a valid email formatpassword: Required string
Delete a user account (authenticated route).
DELETE /users/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): User ID
Response (200 OK):
{
"message": "User deleted successfully"
}Update a user's avatar image (authenticated route).
PATCH /users/avatarHeaders:
Authorization: Bearer <jwt-token>
Content-Type: multipart/form-data
Request Body (Form Data):
avatar: Image file (jpg, png, gif)
Response (200 OK):
{
"id": "uuid-string",
"name": "John Doe",
"email": "john@example.com",
"avatar": "new-avatar-filename.jpg",
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T12:00:00.000Z"
}Retrieve a list of all products (authenticated route).
GET /productsHeaders:
Authorization: Bearer <jwt-token>
Response (200 OK):
[
{
"id": "uuid-string",
"name": "Product Name",
"description": "Product description",
"price": 99.99,
"quantity": 100,
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}
]Retrieve a specific product by its ID (authenticated route).
GET /products/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): Product ID
Response (200 OK):
{
"id": "uuid-string",
"name": "Product Name",
"description": "Product description",
"price": 99.99,
"quantity": 100,
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}Create a new product (authenticated route).
POST /productsHeaders:
Authorization: Bearer <jwt-token>
Request Body:
{
"name": "New Product",
"description": "Product description",
"price": 99.99,
"quantity": 50
}Response (201 Created):
{
"id": "uuid-string",
"name": "New Product",
"description": "Product description",
"price": 99.99,
"quantity": 50,
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T00:00:00.000Z"
}Validation Rules:
name: Required stringdescription: Optional stringprice: Required number with 2 decimal precisionquantity: Required integer
Update an existing product (authenticated route).
PUT /products/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): Product ID
Request Body:
{
"name": "Updated Product",
"description": "Updated description",
"price": 129.99,
"quantity": 75
}Response (200 OK):
{
"id": "uuid-string",
"name": "Updated Product",
"description": "Updated description",
"price": 129.99,
"quantity": 75,
"created_at": "2023-01-01T00:00:00.000Z",
"updated_at": "2023-01-01T12:00:00.000Z"
}Validation Rules:
name: Required stringdescription: Optional stringprice: Required number with 2 decimal precisionquantity: Required integer
Delete a product (authenticated route).
DELETE /products/:idHeaders:
Authorization: Bearer <jwt-token>
URL Parameters:
id(UUID, required): Product ID
Response (200 OK):
{
"message": "Product deleted successfully"
}curl -X POST http://localhost:8080/sessions \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:8080/products \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"name": "New Product",
"description": "Product description",
"price": 99.99,
"quantity": 50
}'curl -X PATCH http://localhost:8080/users/avatar \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-F "avatar=@/path/to/image.jpg"const response = await fetch('http://localhost:8080/sessions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'user@example.com',
password: 'password123'
})
});
const data = await response.json();
console.log(data);const response = await fetch('http://localhost:8080/products', {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
}
});
const products = await response.json();
console.log(products);{
"id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"name": "John Doe",
"email": "john@example.com",
"avatar": null,
"created_at": "2023-12-01T10:30:00.000Z",
"updated_at": "2023-12-01T10:30:00.000Z"
}[
{
"id": "p1q2w3e4-r5t6-y7u8-i9o0-p1a2s3d4f5g6",
"name": "Laptop Computer",
"description": "High-performance laptop for professionals",
"price": 1299.99,
"quantity": 25,
"created_at": "2023-12-01T09:00:00.000Z",
"updated_at": "2023-12-01T09:00:00.000Z"
},
{
"id": "z1x2c3v4-b5n6-m7q8-w9e0-r1t2y3u4i5o6",
"name": "Wireless Mouse",
"description": "Ergonomic wireless mouse with long battery life",
"price": 29.99,
"quantity": 150,
"created_at": "2023-12-01T08:30:00.000Z",
"updated_at": "2023-12-01T08:30:00.000Z"
}
]{
"status": "error",
"message": "\"email\" must be a valid email"
}{
"status": "error",
"message": "JWT Token is missing."
}{
"status": "error",
"message": "User not found"
}{
"status": "error",
"message": "Email address already used."
}- Import the collection from
resource/Insomnia_2022-07-14.json - Set up environment variables:
base_url: http://localhost:8080token: Your JWT token after login
You can test all endpoints using any HTTP client by following the examples above. Make sure to:
- Start the server:
yarn localhost - Set up the database and run migrations
- Use the correct Content-Type headers
- Include Authorization headers for protected routes
Currently, there are no rate limiting restrictions implemented. This should be considered for production environments.
- v1.0.0: Initial API release with Users and Products modules
- Authentication with JWT tokens
- File upload for user avatars
- Complete CRUD operations for all resources
For more information about the project setup and configuration, see the main README.md file.