Subscribed unsubscribe Subscribe Subscribe

フロント用にサクッとAPIのレスポンスを用意するヘ(^o^)ノ

Mock API response with json-server

github.com

Create sample data with Faker.js

github.com

Sample code

github.com

Setup

$ git clone git@github.com:murajun1978/faker-sample.git
$ cd faker-sample 
$ npm install

Start server

$ npm start faker.js

Getting data

$ curl http://localhost:3000/users
[
  {
    "id": 1,
    "name": "Hayden Larkin"
  },
  {
    "id": 2,
    "name": "Mckayla Feest"
  },
  {
    "id": 3,
    "name": "Rowan Schmeler"
  },
  {
    "id": 4,
    "name": "Cyril Grimes"
  },
  {
    "id": 5,
    "name": "Melisa Cremin"
  },
  {
    "id": 6,
    "name": "Deja Corkery II"
  },
  {
    "id": 7,
    "name": "Rod D'Amore"
  },
  {
    "id": 8,
    "name": "Allan Green"
  },
  {
    "id": 9,
    "name": "Jarrod Schoen II"
  },
  {
    "id": 10,
    "name": "Giuseppe Olson"
  }
]

Faker.js

module.exports = function() {
  var faker = require('faker')

  return {
    users: Array.from(Array(10), (_, i) => {
      return {
        id: i + 1,
        name: faker.name.findName()
      }
    })
  }
}

Happy Hacking٩( ‘ω’ )و