node rest - Garuk-solutions/knowledge-base GitHub Wiki

Node js REST API

Introduction to REST API

REST stands for REpresentational State Transfer. It is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other. REST-compliant systems, often called RESTful systems, are characterized by how they are stateless and separate the concerns of client and server.

What is a REST API?

A REST API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data.

Why use REST API?

  • REST API is a simple way to create APIs.
  • REST API is a lightweight and fast way to create APIs.
  • REST API is a scalable way to create APIs.

Packages used in REST API

  • express
  • body-parser

Example

const express = require('express');

const app = express();

const bodyParser = require('body-parser');

app.use(bodyParser.json());

app.use(bodyParser.urlencoded({ extended: true }));

const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});
⚠️ **GitHub.com Fallback** ⚠️