Skip to content

Instantly share code, notes, and snippets.

@yannvery
Last active February 17, 2016 15:05
Show Gist options
  • Save yannvery/d3e5ca46f7f949aee70e to your computer and use it in GitHub Desktop.
Save yannvery/d3e5ca46f7f949aee70e to your computer and use it in GitHub Desktop.
Fake API in 5 minutes

Create a fake api in 5 minutes

I dont't find yet how to do this with ruby, so I use a npm package.

Install json-server

github repository: https://github.com/typicode/json-server

Note: g option has been used to install the package globally (for all users).

npm install -g json-server

Create a database

As a front end developper you don't have installed Postgre or Mysql. Don't forget we have less than 4 minutes now.
Therefore we're creating a json file:

{
  "kings":[
    {
      "id": 1,
      "name": "Edmund lronside",
      "country": "United Kingdom",
      "house": "House of Wessex",
      "years": "1016"
    },
    {
      "id": 2,
      "name": "Cnut",
      "country": "United Kingdom",
      "house": "House of Denameark",
      "years": "1016-1035"
    },
    {
      "id": 3,
      "name": "Harold I Harefoot",
      "country": "United Kingdom",
      "house": "House of Denameark",
      "years": "1035-1040"
    },
    {
      "id": 4,
      "name": "Harthacanut",
      "country": "United Kingdom",
      "house": "House of Denameark",
      "years": "1040-1042"
    },
    {
      "id": 5,
      "name": "Edward the Confessor",
      "country": "United Kingdom",
      "house": "House of Wessex",
      "years": "1042-1066"
    }
  ]
}

Start the server

json-server --watch db.json

You've done it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment