JSON Server - Rest API Installation

json server


JSON Server enables frontend developers to quickly spin up a fake REST API to validate how an app’s interface reacts when receiving data from the backend. This is especially useful when the required backend routes have not been finished yet.

REST stands for representational state transfer and was created by computer scientist Roy Fielding


JSON Server , package

Get a full fake REST API with zero coding in less than 30 seconds (seriously),Created with <3 for front-end developers who need a quick back-end for prototyping and mocking.

JSON Server Package / github.com/typicode/json-server

Installing JSON Server

Before we can send any request, we need to install JSON Server. Preferably, we’d use npm to install the json-server package globally.

Global Installation ::


    npm install -g json-server


Local Installation

  npm install json-server
 


Now that JSON Server has been globally installed, we can create our first server configuration.

Understanding the JSON Server configuration

The next step is to create our first db.json file, which holds the JSON configuration for the fake REST API. Below is a sample configuration, which includes three endpoints: authors, books, and library.

        {
        "authors": [
        { "id": 1, "name": "Michiel Mulders", "genre": "fiction" }
        ],
        "books": [
        { "id": 1, "title": "some title", "authorId": 1 }
        ],
        "library": { "name": "City library" }
    }


Starting your first JSON Server
OR to create db.json 

To start the server and serve the above endpoints, we’ll use the json-server command in the command line. We’ll tell the json-server command to watch our db.json configuration file.


    json-server --watch db.json

OR using NPX you can install json server


  npx json-server --watch db.json

You can verify that your server is running by sending a 
GET request to http://localhost:3000/. If it returns a result, you are ready to explore other endpoints.

after successful installation you will get this kind of output 



G:\json>json-server --watch db.json

  \{^_^}/ hi!

  Loading db.json
  Oops, db.json doesn't seem to exist
  Creating db.json with some default data

  Done

  Resources
  http://localhost:3000/posts
  http://localhost:3000/comments
  http://localhost:3000/profile

  Home
  http://localhost:3000
 


POST MAN : Fake API , Data