Skip to content

Sanidhya22/CRUD-REST-API-with-NODE-JS-Express-and-POSTGRES-DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRUD REST SERVICE WITH VALIDATION and POSTGRESQL AND LAYERED ARCHITECTURE

Installation

  npm i express @hapi/joi cors generate-password pg pg-hstore sequelize uuid

Download Postgres DB and Create DB name "CRUD-DB"

Create Table with below query

CREATE TABLE users (
    id uuid ,
    login VARCHAR NOT NULL,
    password VARCHAR NOT NULL,
    age int NOT NULL,
    isdeleted BOOLEAN,
    PRIMARY KEY (id)
);

Deploy the Server

Run the following command

  node app.js

To test the service CRUD methods, you can use Postman (https://www.getpostman.com/).

Get user by id

  GET http://localhost:3000/items/id/dbcae21d-9bd1-4647-93c3-f53f4fd7b7e4

Get all users data

  GET http://localhost:3000/items/

Get auto-suggest list from limit users, sorted by login property and filtered by loginSubstring in the login property:

  GET http://localhost:3000/items/getASU?login=Dar&limit=3

#### Key ---- Value
##### login  ---- Dar
##### limit ----  3

Create User data

  Post http://localhost:3000/items/

Send user data in Body tab and Select type JSON .
 
 {
        "login": "Darantee",
        "age": "20",
    }

Update User data

  Put http://localhost:3000/items/dbcae21d-9bd1-4647-93c3-f53f4fd7b7e4

  Here "dbcae21d-9bd1-4647-93c3-f53f4fd7b7e4" is the id of user whose data we want to updated.
  Send the updated data in body tab and select JSOn type.
   
   {
        "login": "Shanu",
        "age": "20"
    }

Delete operation will Mark idDeleted "True" in user data

  Delete http://localhost:3000/items/delete/dbcae21d-9bd1-4647-93c3-f53f4fd7b7e4
  
  Here "dbcae21d-9bd1-4647-93c3-f53f4fd7b7e4" is the id of user whose id we want to softdelete.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages