Skip to main content

User Service โ€“ API Reference ๐Ÿ‘ค

This document describes the public and admin APIs exposed by the User Service in ShopVerse.

All APIs are accessed via the API Gateway, and user identity is propagated using gateway-injected headers.


๐ŸŒ Base URLโ€‹


/api/users


๐Ÿ” Authentication & Authorizationโ€‹

  • JWT is validated at the API Gateway
  • Gateway injects:
    • X-User-Email
    • X-User-Role
  • User Service trusts only gateway headers
  • Role-Based Access Control (RBAC) is enforced

๐Ÿ‘ค Get Current User Profileโ€‹

Fetch the profile of the currently authenticated user.

โžค Endpointโ€‹


GET /api/users/me

โžค Headersโ€‹


Authorization: Bearer <JWT>

โžค Success Response (200 OK)โ€‹

{
"id": 1,
"fullName": "John Doe",
"email": "john@example.com",
"phoneNo": "9876543210",
"role": "CUSTOMER",
"createdAt": "2026-01-10T10:15:00"
}

โžค Error Responsesโ€‹

StatusReason
401Unauthorized
500Internal server error

โœ๏ธ Update User Profileโ€‹

Update profile details of the current user.

โžค Endpointโ€‹

PUT /api/users/me

โžค Request Bodyโ€‹

{
"fullName": "John Updated",
"phoneNo": "9123456789"
}

โžค Success Response (200 OK)โ€‹

{
"message": "Profile updated successfully"
}

โžค Error Responsesโ€‹

StatusReason
400Invalid input
403Forbidden
500Internal server error

๐Ÿ  Add Addressโ€‹

Add a new address for the authenticated user.

โžค Endpointโ€‹

POST /api/users/addresses

โžค Request Bodyโ€‹

{
"street": "MG Road",
"city": "Pune",
"state": "Maharashtra",
"pincode": "411001"
}

โžค Success Response (201 CREATED)โ€‹

{
"message": "Address added successfully"
}

๐Ÿ“ Get User Addressesโ€‹

Fetch all addresses belonging to the authenticated user.

โžค Endpointโ€‹

GET /api/users/addresses

โžค Success Response (200 OK)โ€‹

[
{
"id": 101,
"street": "MG Road",
"city": "Pune",
"state": "Maharashtra",
"pincode": "411001"
}
]

๐Ÿ“ Update Addressโ€‹

Update an existing address owned by the user.

โžค Endpointโ€‹

PUT /api/users/addresses/{addressId}

โžค Request Bodyโ€‹

{
"street": "FC Road",
"city": "Pune",
"state": "Maharashtra",
"pincode": "411004"
}

โžค Success Response (200 OK)โ€‹

{
"message": "Address updated successfully"
}

โŒ Delete Addressโ€‹

Delete an address owned by the user.

โžค Endpointโ€‹

DELETE /api/users/addresses/{addressId}

โžค Success Response (204 NO CONTENT)โ€‹


๐Ÿ‘‘ Admin โ€“ Get All Usersโ€‹

Fetch all users (admin-only).

โžค Endpointโ€‹

GET /api/users

โžค Role Requiredโ€‹

ADMIN

โžค Success Response (200 OK)โ€‹

[
{
"id": 1,
"email": "admin@shopverse.com",
"role": "ADMIN"
},
{
"id": 2,
"email": "user@shopverse.com",
"role": "CUSTOMER"
}
]

โŒ Admin โ€“ Delete Userโ€‹

Delete a user by ID (admin-only).

โžค Endpointโ€‹

DELETE /api/users/{userId}

โžค Role Requiredโ€‹

ADMIN

โžค Success Response (204 NO CONTENT)โ€‹


๐Ÿ›ก๏ธ Authorization Rules Summaryโ€‹

RoleAllowed Actions
CUSTOMERManage own profile & addresses
ADMINManage all users

Ownership is enforced using X-User-Email.


๐Ÿ”„ Request Flowโ€‹


โš ๏ธ Common Errorsโ€‹

StatusMeaning
401Invalid or missing token
403Access denied
404Resource not found
409Conflict (duplicate data)

๐Ÿ“Œ Summaryโ€‹

The User API provides:

  • Secure access to user profiles
  • Strict ownership enforcement
  • Clean separation of admin and user actions
  • Gateway-based authentication trust model

It ensures user data integrity and security in ShopVerse.