json server

通过json文件,快速搭建api服务。

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

Getting started

#install
npm install -g json-server

Create a db.json file with some data

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

Start JSON Server

json-server --watch db.json

Now if you go to http://localhost:3000/posts/1, you'll get

{ "id": 1, "title": "json-server", "author": "typicode" }

You can start JSON Server on other ports with the --portflag:

json-server --watch db.json --port 3004

Remote schema

you can load remote schemas.

$ json-server http://example.com/file.json
$ json-server http://jsonplaceholder.typicode.com/db

results matching ""

    No results matching ""