DEV Community

loizenai
loizenai

Posted on

Node.js/Express RestAPIs Example – POST/GET/PUT/DELETE requests

https://ozenero.com/nodejs-restapis-how-to-create-nodejs-express-restapis-post-get-put-delete-requests

Node.js/Express RestAPIs Example – POST/GET/PUT/DELETE requests

In the tutorial, we're gonna look at way to create NodeJs/Express RestAPIs with Post/Get/Put/Delete requests.

Related posts:

Overview

Demo

Goal

We create a NodeJs/Express RestAPIs project that has structure as below:

nodejs express - restapis - project structure


/nodejs-restapi
    /app
        /controllers
            customer.controller.js
        /routes
            customer.routes.js
    /node-modules
    package.json
    package-lock.json
    server.js

The project create a set of Rest-APIs for POST/GET/UPDATE/DELETE APIs:

  • /api/customers - GET all customers
  • /api/customers/:id - GET a customer by Id
  • '/api/customers - POST a customer
  • /api/customers/update/:id - UPDATE a customer by Id
  • /api/customers/delete/:id - DELETE a customer by Id

Setup NodeJs/Express project

Use NPM to create a Node/Express project as the guide

Create application directory


mkdir nodejs-restapi
cd nodejs-restapi

Create package.json file

Use the npm init to create ‘package.json’ file:

More at:

https://ozenero.com/nodejs-restapis-how-to-create-nodejs-express-restapis-post-get-put-delete-requests

Node.js/Express RestAPIs Example – POST/GET/PUT/DELETE requests

Top comments (0)