This document covers all user-related endpoints in the Chirpy API.
The Users API allows you to create and manage user accounts. All user operations except registration require authentication.
All user endpoints are prefixed with /api
Create a new user account.
Authentication: Not required
Request Body:
{
"email": "user@example.com",
"password": "securepassword123"
}Response (201 Created):
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "user@example.com",
"is_chirpy_red": false,
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z"
}Error Responses:
400 Bad Request- Invalid JSON, missing email/password, or validation errors500 Internal Server Error- Server error (possibly duplicate email)
Example:
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"email": "newuser@example.com", "password": "securepassword123"}'Update an existing user's information.
Authentication: Required (Bearer token)
Request Headers:
Authorization: Bearer <access_token>
Content-Type: application/json
Request Body:
{
"email": "newemail@example.com",
"password": "newpassword123"
}Response (200 OK):
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "newemail@example.com",
"is_chirpy_red": false,
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T12:00:00Z"
}Error Responses:
400 Bad Request- Invalid JSON, missing email/password, or validation errors401 Unauthorized- Invalid, expired, or missing access token500 Internal Server Error- Server error
Example:
curl -X PUT http://localhost:8080/api/users \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{"email": "updated@example.com", "password": "newpassword123"}'{
"id": "123e4567-e89b-12d3-a456-426614174000",
"email": "user@example.com",
"is_chirpy_red": false,
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z"
}Fields:
id(UUID) - Unique identifier for the useremail(string) - User's email address (must be unique)is_chirpy_red(boolean) - Premium subscription statuscreated_at(timestamp) - When the user account was createdupdated_at(timestamp) - When the user account was last updated
- Must be a valid email format
- Must be unique across all users
- Required for both registration and updates
- No minimum length enforced by API (implement client-side validation)
- Required for both registration and updates
- Stored as bcrypt hash (never returned in responses)
The is_chirpy_red field indicates whether a user has premium features:
false- Standard usertrue- Premium user with Chirpy Red features
Note: Users cannot directly update their premium status through the API. Premium upgrades are handled through the Webhooks API.
- Password Security: Passwords are hashed using bcrypt and never returned in API responses
- Email Uniqueness: The system enforces unique email addresses
- Authentication: User updates require a valid access token
- User Isolation: Users can only update their own information
User endpoints return appropriate HTTP status codes:
200 OK- Successful update201 Created- Successful registration400 Bad Request- Invalid request data or validation errors401 Unauthorized- Authentication required or failed500 Internal Server Error- Server error
Error responses include a plain text message in the response body.
After creating a user account:
- Use the Authentication API to log in
- Use the returned access token for authenticated requests
- Update user information using the access token
-
Registration:
curl -X POST http://localhost:8080/api/users \ -H "Content-Type: application/json" \ -d '{"email": "john@example.com", "password": "password123"}'
-
Login:
curl -X POST http://localhost:8080/api/login \ -H "Content-Type: application/json" \ -d '{"email": "john@example.com", "password": "password123"}'
-
Update Profile:
curl -X PUT http://localhost:8080/api/users \ -H "Authorization: Bearer <access_token>" \ -H "Content-Type: application/json" \ -d '{"email": "john.doe@example.com", "password": "newpassword123"}'