Project 2 - API Documentation
API Documentation
Section titled “API Documentation”Complete REST API reference for Project 2.
Base URL
Section titled “Base URL”Production: https://api.project2.com/v1Development: http://localhost:3000/v1Authentication
Section titled “Authentication”All API requests require authentication via JWT token:
Authorization: Bearer <your-token>POST /auth/login
Section titled “POST /auth/login”Login with email and password.
Request:
{ "email": "user@example.com", "password": "SecurePassword123"}Response:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "user": { "id": "123", "email": "user@example.com", "name": "John Doe" }}POST /auth/register
Section titled “POST /auth/register”Create a new user account.
Request:
{ "email": "user@example.com", "password": "SecurePassword123", "name": "John Doe"}Response:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "user": { "id": "123", "email": "user@example.com", "name": "John Doe" }}Users API
Section titled “Users API”GET /users/:id
Section titled “GET /users/:id”Get user details by ID.
Response:
{ "id": "123", "email": "user@example.com", "name": "John Doe", "createdAt": "2025-01-01T00:00:00Z"}PUT /users/:id
Section titled “PUT /users/:id”Update user profile.
Request:
{ "name": "Jane Doe", "bio": "Software developer"}Products API
Section titled “Products API”GET /products
Section titled “GET /products”List all products with pagination.
Query Parameters:
page(number): Page number (default: 1)limit(number): Items per page (default: 20)sort(string): Sort field (default: createdAt)
Response:
{ "products": [...], "total": 100, "page": 1, "pages": 5}POST /products
Section titled “POST /products”Create a new product (Admin only).
Request:
{ "name": "Product Name", "description": "Product description", "price": 99.99, "stock": 100}Error Handling
Section titled “Error Handling”All errors follow this format:
{ "error": { "code": "VALIDATION_ERROR", "message": "Invalid email format", "details": { "field": "email" } }}Status Codes
Section titled “Status Codes”200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found429- Too Many Requests500- Internal Server Error
Official SDKs available for:
- JavaScript/TypeScript
- Python
- Go
- Ruby