Skip to main content
The Users API provides endpoints for retrieving and updating user information. All endpoints require authentication.

GET /api/users/:id

Retrieve a user by their ID.

Authentication

Required. Include JWT token in Authorization header.

Path Parameters

id
integer
required
User ID

Response

user
object
User information in JSON format

Example Request

curl -X GET http://localhost:3000/api/users/1 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

{
  "user": {
    "id": 1,
    "email": "[email protected]",
    "name": "John Doe",
    "role": "customer",
    "profile": null,
    "createdAt": "2026-03-01T10:00:00.000Z",
    "updatedAt": "2026-03-01T10:00:00.000Z"
  }
}

GET /api/users/me/profile

Retrieve the authenticated user’s profile.

Authentication

Required. The user ID is extracted from the JWT token.

Response

user
object
Formatted user profile information

Example Request

curl -X GET http://localhost:3000/api/users/me/profile \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

{
  "user": {
    "id": 1,
    "email": "[email protected]",
    "name": "John Doe",
    "avatar": "https://example.com/avatar.jpg",
    "bio": "Software developer",
    "phone": "+1234567890"
  }
}

Error Responses

  • 401 Unauthorized - Missing or invalid authentication token
  • 500 Internal Server Error - Failed to fetch profile

PUT /api/users/me/profile

Update the authenticated user’s profile.

Authentication

Required. The user ID is extracted from the JWT token.

Request Body

avatar
string
URL to user’s avatar image
bio
string
User’s biography or description
phone
string
User’s phone number

Response

message
string
Success message
user
object
Updated user information in JSON format

Example Request

curl -X PUT http://localhost:3000/api/users/me/profile \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "avatar": "https://example.com/new-avatar.jpg",
    "bio": "Full-stack developer passionate about Node.js",
    "phone": "+1234567890"
  }'

Example Response

{
  "message": "Profile updated successfully",
  "user": {
    "id": 1,
    "email": "[email protected]",
    "name": "John Doe",
    "role": "customer",
    "profile": {
      "avatar": "https://example.com/new-avatar.jpg",
      "bio": "Full-stack developer passionate about Node.js",
      "phone": "+1234567890"
    },
    "createdAt": "2026-03-01T10:00:00.000Z",
    "updatedAt": "2026-03-03T14:30:00.000Z"
  }
}

Error Responses

  • 401 Unauthorized - Missing or invalid authentication token
  • 500 Internal Server Error - Failed to update profile

Build docs developers (and LLMs) love