Skip to content

matenka-andrii/rest-api-nodejs-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API with Node.js, Express.js and PostgreSQL

To start, follow the instructions:

  1. Clone the repository:
  1. Change into the project directory:
  • cd rest-api-nodejs-mongodb
  1. Install dependencies:
  • npm install
  1. Create a .env file in the root directory of the project with the following contents:
  • DB_URL=postgres:https://********:e_oetdO********@flora.db.elephantsql.com/******** You can get that url using https://www.elephantsql.com/
  • PORT=3000
  1. Start the server:
  • npm run start:dev

After completing the above steps, the server should be running and accessible at http:https://localhost:3000.

Using Postman to Fetch Endpoints

This section provides detailed information about the available endpoints that can be accessed using Postman.

Available Endpoints

Create Category

  • Method: POST
  • Endpoint: /categories
  • Body: JSON object containing the category's details. Fields required are as follows:
{
  "name": "YourCategoryName",
}

Get Categories

  • 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.

Other endpoints:

  • Update category: PUT /categories/:id
  • Delete category: DELETE /categories/:id

Create Product

  • 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,
}

Other endpoints:

  • 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

About

REST API with Node.js, Express.js and PostgreSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published