POST /login
Authenticate a user and return a Bearer token.
{
"email": "user@example.com",
"password": "password123"
}
curl --request POST \
--url http://localhost:3333/login \
--header 'Content-Type: application/json' \
--data '{
"email": "user@example.com",
"password": "password123"
}'
- Method: POST
- URL:
http://localhost:3333/login
- Body: Raw JSON
{
"email": "user@example.com",
"password": "password123"
}
{
"type": "bearer",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"username": "budi",
"email": "budi@example.com",
"roleId": 1,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
}
}
GET /users
Get a list of all users.
curl --request GET \
--url http://localhost:3333/users \
--header 'Authorization: Bearer <your_token>'
- Method: GET
- URL:
http://localhost:3333/users
- Authorization: Bearer Token
[
{
"id": 1,
"username": "budi",
"email": "budi@example.com",
"roleId": 1,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
},
{
"id": 2,
"username": "siti",
"email": "siti@example.com",
"roleId": 2,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
}
]
GET /users/:id
Retrieve a specific user by their ID.
curl --request GET \
--url http://localhost:3333/users/1 \
--header 'Authorization: Bearer <your_token>'
- Method: GET
- URL:
http://localhost:3333/users/1
- Authorization: Bearer Token
{
"id": 1,
"username": "budi",
"email": "budi@example.com",
"roleId": 1,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
}
POST /users
Create a new user.
{
"username": "agus",
"email": "agus@example.com",
"password": "password123",
"roleId": 3
}
curl --request POST \
--url http://localhost:3333/users \
--header 'Authorization: Bearer <your_token>' \
--header 'Content-Type: application/json' \
--data '{
"username": "agus",
"email": "agus@example.com",
"password": "password123",
"roleId": 3
}'
- Method: POST
- URL:
http://localhost:3333/users
- Body: Raw JSON
- Authorization: Bearer Token
{
"username": "agus",
"email": "agus@example.com",
"password": "password123",
"roleId": 3
}
{
"id": 3,
"username": "agus",
"email": "agus@example.com",
"roleId": 3,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
}
PUT /users/:id
Update a user’s details by ID.
{
"username": "agus",
"email": "agus@example.com"
}
curl --request PUT \
--url http://localhost:3333/users/3 \
--header 'Authorization: Bearer <your_token>' \
--header 'Content-Type: application/json' \
--data '{
"username": "agus",
"email": "agus@example.com"
}'
- Method: PUT
- URL:
http://localhost:3333/users/3
- Body: Raw JSON
- Authorization: Bearer Token
{
"username": "agus",
"email": "agus@example.com"
}
{
"id": 3,
"username": "agus",
"email": "agus@example.com",
"roleId": 3,
"createdAt": "2024-09-03T06:09:36.000Z",
"updatedAt": "2024-09-03T06:09:36.000Z"
}
DELETE /users/:id
Delete a user by ID.
curl --request DELETE \
--url http://localhost:3333/users/3 \
--header 'Authorization: Bearer <your_token>'
- Method: DELETE
- URL:
http://localhost:3333/users/3
- Authorization: Bearer Token
GET /locations
Get a list of all locations.
curl --request GET \
--url http://localhost:3333/locations \
--header 'Authorization: Bearer <your_token>'
- Method: GET
- URL:
http://localhost:3333/locations
- Authorization: Bearer Token
GET /locations/:id
Retrieve a specific location by its ID.
curl --request GET \
--url http://localhost:3333/locations/1 \
--header 'Authorization: Bearer <your_token>'
GET /barns
Get a list of all barns.
curl --request GET \
--url http://localhost:3333/barns \
--header 'Authorization: Bearer <your_token>'
GET /floors
Get a list of all floors.
curl --request GET \
--url http://localhost:3333/floors \
--header 'Authorization: Bearer <your_token>'
GET /stocks
Get a list of all stocks.
curl --request GET \
--url http://localhost:3333/stocks \
--header 'Authorization: Bearer <your_token>'
GET /stock-histories
Get a list of all stock histories.
curl --request GET \
--url http://localhost:3333/stock-histories \
--header 'Authorization: Bearer <your_token>'
These routes require the Authorization
header with a valid Bearer token to access. The Bearer token
is obtained from the login response.
Authorization: Bearer <your_token>
This provides a comprehensive guide on how to interact with the API using either Postman or curl
. Each route includes the HTTP method, endpoint, required