- Clone the repository:
git clone [email protected]:matenka-andrii/rest-api-nodejs-postgresql.git
- Change into the project directory:
cd rest-api-nodejs-mongodb
- Install dependencies:
npm install
- Create a
.env
file in the root directory of the project with the following contents:
DB_URL=postgres://********:e_oetdO********@flora.db.elephantsql.com/********
You can get that url using https://www.elephantsql.com/PORT=3000
- Start the server:
npm run start:dev
After completing the above steps, the server should be running and accessible at http://localhost:3000.
This section provides detailed information about the available endpoints that can be accessed using Postman.
- Method: POST
- Endpoint: /categories
- Body: JSON object containing the category's details. Fields required are as follows:
{
"name": "YourCategoryName",
}
- Method: GET
- Endpoint: /categories
- Returns: This endpoint returns a JSON array of categories. Each category object contains an ID and a name attribute.
[
{
"id": 1,
"name": "Technology"
},
{
"id": 2,
"name": "Science"
}
]
- Description: Use this endpoint to fetch a list of all categories available in the system.
- Update category:
PUT /categories/:id
- Delete category:
DELETE /categories/:id
- Method: POST
- Endpoint: /products
- Body: JSON object containing the product's details. Fields required are as follows:
{
"name": "YourProductName",
"description": "Product description ...",
"price": 49.99,
"currency": "USD",
"quantity": 1,
"active": true,
"category_id": 1,
}
- Get products:
GET /products
- Get product by id:
GET /products/:id
- Get products by category:
GET /products/category/:categoryId
- Update product:
PUT /products/:id
- Delete product:
DELETE /products/:id