API Reference

Comprehensive documentation for the My Awesome Project API

Users

GET /api/v1/users

Retrieves a list of all users.

Responses

Success (200 OK)

Returns an array of user objects.


[
  {
    "id": 1,
    "username": "alice",
    "email": "alice@example.com",
    "created_at": "2023-10-27T10:00:00Z"
  },
  {
    "id": 2,
    "username": "bob",
    "email": "bob@example.com",
    "created_at": "2023-10-27T10:05:00Z"
  }
]
                        
GET /api/v1/users/{userId}

Retrieves a specific user by their ID.

Parameters

Name Type Required Description
userId integer Yes The unique identifier of the user.

Responses

Success (200 OK)

Returns the user object.


{
  "id": 1,
  "username": "alice",
  "email": "alice@example.com",
  "created_at": "2023-10-27T10:00:00Z"
}
                        

Not Found (404 Not Found)

If the user with the specified ID does not exist.


{
  "error": "User not found"
}
                        
POST /api/v1/users

Creates a new user.

Request Body

Requires a JSON object with user details.


{
  "username": "new_user",
  "email": "new@example.com",
  "password": "secure_password_123"
}
                        

Responses

Created (201 Created)

Returns the newly created user object.


{
  "id": 3,
  "username": "new_user",
  "email": "new@example.com",
  "created_at": "2023-10-27T10:15:00Z"
}
                        

Bad Request (400 Bad Request)

If required fields are missing or invalid.


{
  "error": "Invalid input data",
  "details": ["Email is already in use"]
}
                        

Products

GET /api/v1/products

Retrieves a list of all available products.

Responses

Success (200 OK)


[
  {
    "id": 101,
    "name": "Laptop Pro",
    "price": 1200.00,
    "description": "High-performance laptop for professionals."
  },
  {
    "id": 102,
    "name": "Wireless Mouse",
    "price": 25.50,
    "description": "Ergonomic wireless mouse."
  }
]
                        

Orders

POST /api/v1/orders

Creates a new order for the authenticated user.

Request Body


{
  "items": [
    { "productId": 101, "quantity": 1 },
    { "productId": 102, "quantity": 2 }
  ],
  "shippingAddress": "123 Main St, Anytown, USA"
}
                        

Responses

Created (201 Created)

Returns the newly created order details.


{
  "orderId": "ORD789012",
  "userId": 1,
  "totalAmount": 1251.00,
  "status": "pending",
  "createdAt": "2023-10-27T10:30:00Z"
}
                        

Authentication

POST /api/v1/auth/login

Logs in a user and returns an authentication token.

Request Body


{
  "email": "alice@example.com",
  "password": "your_password"
}
                        

Responses

Success (200 OK)


{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ey..."
}
                        

Unauthorized (401 Unauthorized)

If credentials are invalid.


{
  "error": "Invalid credentials"
}