Create JSON Server API for Angular

For the Fake backend server, we will setup JSON Server for Angular CRUD (Fake REST API).

1. Install JSON Server

Install the JSON server using the command below


npm install -g json-server

2. Create API File

Now, we will create a file db.json in the project root.


{
  "users": [
    { "id": 1, "name": "John", "email": "john@gmail.com", "salary": 35000 },
    { "id": 2, "name": "Tom", "email": "tom@gmail.com", "salary": 25000 },
    { "id": 3, "name": "Matt", "email": "matt@gmail.com", "salary": 22000 }
  ]
}

3. Run JSON Server

After creating a API, then will run through below command


json-server --watch db.json --port 3000

Now, we can check the API through the URL below


http://localhost:3000/users