This document provides instructions for interacting with the Node server and details the available APIs and their endpoints.
To run the server, execute the following command:
node server.js
The server will run on the following base URL:
http://localhost:8080
This endpoint retrieves a list of products.
- HTTP Method: GET
- URL:
/products
- None
- Status: 200 OK
- Content-Type: application/json
Example Response:
[
{
"id": ...,
"title": ...,
...
},
{
"id": ...,
"title": ...,
...
}
]
This endpoint retrieves a specific product by ID.
- HTTP Method: GET
- URL:
/products?id=2
- id (required): The ID of the product.
- Status: 200 OK
- Content-Type: application/json
Example Response:
{
"id": ...,
"title": ...,
...
}
This endpoint retrieves a list of users.
- HTTP Method: GET
- URL:
/users
- None
- Status: 200 OK
- Content-Type: application/json
Example Response:
[
{
"id": ...,
"username": ...,
...
},
{
"id": ...,
"username": ...,
...
}
]
This endpoint retrieves a specific user by username.
- HTTP Method: GET
- URL:
/users?username=john
- username (required): The username of the user.
- Status: 200 OK
- Content-Type: application/json
Example Response:
{
"id": ...,
"username": ...,
...
}
This endpoint retrieves a specific user based on the provided username and password in the request body.
- HTTP Method: POST
- URL:
/login
- username (required): The username of the user.
- password (required): The password of the user.
- Status: 200 OK
- Content-Type: application/json
Example Response:
{
"id": ...,
"username": ...,
...
}