with a Postman API documentation for the authentication module we’ve created, including JSON code examples for each endpoint. This documentation will use http://localhost:5000/api/auth/ as the base URL.
Here’s the Postman API documentation for your authentication module:
- User Registration
- URL:
http://localhost:5000/api/auth/register - Method: POST
- Body (raw JSON):
{
"username": "newuser",
"email": "newuser@example.com",
"password": "password123"
}- Response (201 Created):
{
"message": "User registered successfully!",
"userId": 1
}- User Login
- URL:
http://localhost:5000/api/auth/login - Method: POST
- Body (raw JSON):
{
"username": "newuser",
"password": "password123"
}- Response (200 OK):
{
"id": 1,
"username": "newuser",
"email": "newuser@example.com",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Protected Route Example
- URL:
http://localhost:5000/api/auth/protected - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "This is a protected route."
}Admin Route Example
- URL:
http://localhost:5000/api/auth/admin - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "This is an admin route."
}- Create Group
- URL:
http://localhost:5000/api/auth/groups - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"name": "Administrators"
}- Response (201 Created):
{
"id": 1,
"name": "Administrators"
}- Get All Groups
- URL:
http://localhost:5000/api/auth/groups - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
[
{
"id": 1,
"name": "Administrators"
},
{
"id": 2,
"name": "Users"
}
]- Get Group by ID
- URL:
http://localhost:5000/api/auth/groups/1 - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"id": 1,
"name": "Administrators"
}- Update Group
- URL:
http://localhost:5000/api/auth/groups/1 - Method: PUT
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"name": "Super Administrators"
}- Response (200 OK):
{
"id": 1,
"name": "Super Administrators"
}- Delete Group
- URL:
http://localhost:5000/api/auth/groups/1 - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "Group deleted successfully."
}- Create Permission
- URL:
http://localhost:5000/api/auth/permissions - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"name": "Can view users",
"codename": "view_users"
}- Response (201 Created):
{
"id": 1,
"name": "Can view users",
"codename": "view_users"
}- Get All Permissions
- URL:
http://localhost:5000/api/auth/permissions - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
[
{
"id": 1,
"name": "Can view users",
"codename": "view_users"
},
{
"id": 2,
"name": "Can edit users",
"codename": "edit_users"
}
]- Get Permission by ID
- URL:
http://localhost:5000/api/auth/permissions/1 - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"id": 1,
"name": "Can view users",
"codename": "view_users"
}- Update Permission
- URL:
http://localhost:5000/api/auth/permissions/1 - Method: PUT
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"name": "Can view and edit users",
"codename": "view_edit_users"
}- Response (200 OK):
{
"id": 1,
"name": "Can view and edit users",
"codename": "view_edit_users"
}- Delete Permission
- URL:
http://localhost:5000/api/auth/permissions/1 - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "Permission deleted successfully."
}- Assign Permission to Group
- URL:
http://localhost:5000/api/auth/groups/1/permissions - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionId": 2
}- Response (200 OK):
{
"message": "Permission assigned to group successfully."
}- Remove Permission from Group
- URL:
http://localhost:5000/api/auth/groups/1/permissions/2 - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "Permission removed from group successfully."
}Assign multiple permissions to a group:
- URL:
http://localhost:5000/api/auth/groups/1/permissions/bulk - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionIds": [1, 2, 3, 4]
Response (200 OK):Remove multiple permissions from a group:
- URL:
http://localhost:5000/api/auth/groups/1/permissions/bulk - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionIds": [2, 4]
}{
"message": "Permissions removed from group successfully."
}- Assign Permission to User
- URL:
http://localhost:5000/api/auth/users/1/permissions - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionId": 2
}- Response (200 OK):
{
"message": "Permission assigned to user successfully."
}- Remove Permission from User
- URL:
http://localhost:5000/api/auth/users/1/permissions/2 - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "Permission removed from user successfully."
Assign multiple permissions to a user:
- URL:
http://localhost:5000/api/auth/users/1/permissions/bulk - Method: POST
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionIds": [1, 3, 5]
}Remove multiple permissions from a user:
- URL:
http://localhost:5000/api/auth/users/1/permissions/bulk - Method: DELETE
- Headers:
- x-access-token:
<your_jwt_token> - Body (raw JSON):
{
"permissionIds": [3, 5]
}- Protected Route Example
- URL:
http://localhost:5000/api/auth/protected - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "This is a protected route."
}- Admin Route Example
- URL:
http://localhost:5000/api/auth/admin - Method: GET
- Headers:
- x-access-token:
<your_jwt_token> - Response (200 OK):
{
"message": "This is an admin route."
}To use these endpoints in Postman:
- Create a new request for each endpoint.
- Set the HTTP method and URL as specified.
- For routes requiring authentication, add the
x-access-tokenheader with the JWT token you received from the login route. - For POST and PUT requests, set the body to “raw” and select JSON format, then input the provided JSON payload.
- Send the request and check the response.
Remember to replace any placeholder IDs (like :id, :userId, :groupId, :permissionId) with actual IDs when testing these endpoints. Also, ensure your server is running on http://localhost:5000 before testing these endpoints.