Welcome to the Mini Twitter API documentation. This guide provides a comprehensive overview of the available API endpoints for the User Service, including detailed descriptions, example requests, and responses.
Create a User
Endpoint: POST /api/users
Description: Creates a new user in the system.
Request Body:
{
"username": "johndoe",
"email": "johndoe@example.com",
"password": "password123",
"name": "John Doe",
"bio": "A passionate coder."
}
Response Body (Success):
{
"data": "OK"
}
Response Body (Failed):
{
"errors": "Username or email already exists."
}
Login User
Endpoint: POST /api/auth/login
Description: uthenticates a user and returns a token.
- Request Body:
{
"username": "johndoe",
"password": "password123"
}
Response Body (Success):
{
"data": {
"token": "jwt-token-example",
"expiredAt": 1694538000000
}
}
Response Body (Failed):
{
"errors": "Username or password wrong."
}
Logout User
Endpoint: DELETE /api/auth/logout
Description: Logs out a user by invalidating their token.
Request Header:
X-API-TOKEN
: The user's authentication token (Mandatory).
Response Body (Success):
{
"data": "OK"
}
Response Body (Failed):
{
"errors": "Error logging out user."
}
Update User
Endpoint: PUT /api/users/{userId}
Description: Updates the information of an existing user. The user must be authenticated to update their profile.
Request Parameters::
useId
: The unique identifier of the user whose profile is being updated.
Request Header:
-
X-API-TOKEN
: The user's authentication token (Mandatory). -
Request Body:
{
"email": "newemail@example.com",
"password": "newpassword123",
"name": "New Name",
"bio": "Updated bio."
}
Response Body (Success):
{
"data": {
"id": "user-123",
"username": "johndoe",
"email": "newemail@example.com",
"name": "New Name",
"bio": "Updated bio."
}
}
Response Body (Failed):
{
"errors": "User not found or validation error."
}
Fetch User Profile
Endpoint: GET /api/users/{userId}
Description: Retrieves details of a specific user by their ID.
Request Parameters::
userId
: The unique identifier of the user whose profile is being fetched.
Response Body (Success):
{
"data": {
"id": "user-123",
"username": "johndoe",
"email": "johndoe@example.com",
"name": "John Doe",
"bio": "A passionate coder."
}
}
Response Body (Failed):
{
"errors": "User not found."
}