Creating a simple REST server

For testing purposes I needed a quick and dirty way to create a REST server to server data. I found a very basic and easy to use REST server that stores data inside a JSON file. It is called json-server. Any changes you make will be saved to the JSON file.

Getting it up and running is very easy.

Install json-server:

npm install -g json-server

Create a JSON file containing the data, e.g. db.json:

    "products": [{
        "id": 1, "name": "coat", "price": 100.00
    }, {
        "id": 2, "name": "hat", "price": 30.00 
    }, { 
        "id": 3, "name": "umbrella", "price": 10.00 

Start json-server:

json-server --watch db.json

Now go to http://localhost:3000/products/1 and you will get:

{ "id": 1, "name": "coat", "price": 100.00 }

Check out the json-server GitHub page for all the other cool stuff you can do.

Happy coding.