1.0.0-alpha.23 • Published 3 months ago

json-server v1.0.0-alpha.23

Weekly downloads
157,280
License
SEE LICENSE IN ./...
Repository
-
Last release
3 months ago

!IMPORTANT Viewing alpha v1 documentation – usable but expect breaking changes. For stable version, see here

json-server

Node.js CI

Install

npm install json-server

Usage

Create a db.json or db.json5 file

{
  "posts": [
    { "id": "1", "title": "a title", "views": 100 },
    { "id": "2", "title": "another title", "views": 200 }
  ],
  "comments": [
    { "id": "1", "text": "a comment about post 1", "postId": "1" },
    { "id": "2", "text": "another comment about post 1", "postId": "1" }
  ],
  "profile": {
    "name": "typicode"
  }
}
{
  posts: [
    { id: '1', title: 'a title', views: 100 },
    { id: '2', title: 'another title', views: 200 },
  ],
  comments: [
    { id: '1', text: 'a comment about post 1', postId: '1' },
    { id: '2', text: 'another comment about post 1', postId: '1' },
  ],
  profile: {
    name: 'typicode',
  },
}

You can read more about JSON5 format here.

Pass it to JSON Server CLI

$ npx json-server db.json

Get a REST API

$ curl http://localhost:3000/posts/1
{
  "id": "1",
  "title": "a title"
}

Run json-server --help for a list of options

Sponsors ✨

Sponsors

Become a sponsor and have your company logo here

Routes

Based on the example db.json, you'll get the following routes:

GET    /posts
GET    /posts/:id
POST   /posts
PUT    /posts/:id
PATCH  /posts/:id
DELETE /posts/:id

# Same for comments
GET   /profile
PUT   /profile
PATCH /profile

Params

Conditions

  • ==
  • lt<
  • lte<=
  • gt>
  • gte>=
  • ne!=
GET /posts?views_gt=9000

Range

  • start
  • end
  • limit
GET /posts?_start=10&_end=20
GET /posts?_start=10&_limit=10

Paginate

  • page
  • per_page (default = 10)
GET /posts?_page=1&_per_page=25

Sort

  • _sort=f1,f2
GET /posts?_sort=id,-views

Nested and array fields

  • x.y.z...
  • x.y.z[i]...
GET /foo?a.b=bar
GET /foo?x.y_lt=100
GET /foo?arr[0]=bar

Embed

GET /posts?_embed=comments
GET /comments?_embed=post

Delete

DELETE /posts/1
DELETE /posts/1?_dependent=comments

Serving static files

If you create a ./public directory, JSON Serve will serve its content in addition to the REST API.

You can also add custom directories using -s/--static option.

json-server -s ./static
json-server -s ./static -s ./node_modules

License

This project uses the Fair Source License. Note: Only organizations with 3+ users need to contribute a small amount through sponsorship sponsor for usage. This license helps keep the project sustainable and healthy, benefiting everyone.

For more information, FAQs, and the rationale behind this, visit https://fair.io/.

@muros-ct/angular-plotlyjs-api-starteractive-react-scriptsrc-ui-designerrc-ui-cmpmat-typeahead-library-testtestp-cmpskandjerverdarth-orga-uidarth-privilege-ui@mediator-legal/uinote-manager@sanofi-iadc/qc-tablegit-lifelv2500@startdt/cli-test-utilssa-template-react@startdt/next-test-utilscopysh-message-randomcra-template-ifunplus@kappasquare/eskimo@edwardmx/mockserverw-mock@infinitebrahmanuniverse/nolb-json-sdungyourluv-botfb@pojntfx-incubator/complex-schema-microservice-mockupdarth-orgareact-tagilize@everything-registry/sub-chunk-1985basics-react-ts-sankeytmforumtmforum-newheatwavesheaderfileice-react-uigroceriesdeliverygrunt-appverse-jsonservergrunt-json-serverinnov-boxgulp-server-iogulp-json-servergulp-json-srv-forkedgulp-json-srvhappymockhash8-platformhw-knowledge-management-json-serverhieunv_iiotprotocolgigantic_sausagegraphql-boilerplate-simpleserverfrenzy.jsformtrainingjojo-mockjord_global_pickers_newjsdoc-json-livejson-server-extensionjson-server-mockyjson-server-routerjson-server-simplejson-server-sxtensionjson-serverless-libjson-data-serverjson-nowkakashi.jsjslib-test-utilsjsonserver-fake-authkyoul-payhematology_clientoptee_modalem-pipefruit-apifetchbookfastfoodexpress-auto-serverexpress-json-serverfoodie_4foodorder-applicationfoodhubflexmockeasy-react-scriptsearth-scriptsearth-scripts-ssreasy-service-clielectron-react-templatefake-photosfe.mock-apife-codefake-data-generategenesis-uimobin-tagmobin-tagilizemo-servemock-local-servermock-rest-apimockingjay.jsmocker-server-clilowservermacondo-mockjsongrok-serverjsonplaceholder
1.0.0-alpha.23

3 months ago

1.0.0-alpha.22

3 months ago

1.0.0-alpha.21

3 months ago

1.0.0-alpha.20

3 months ago

1.0.0-alpha.19

3 months ago

1.0.0-alpha.18

3 months ago

1.0.0-alpha.17

3 months ago

1.0.0-alpha.16

3 months ago

1.0.0-alpha.15

3 months ago

1.0.0-alpha.14

3 months ago

1.0.0-alpha.12

3 months ago

1.0.0-alpha.11

3 months ago

1.0.0-alpha.13

3 months ago

1.0.0-alpha.10

3 months ago

1.0.0-alpha.9

4 months ago

1.0.0-alpha.8

4 months ago

1.0.0-alpha.7

4 months ago

1.0.0-alpha.6

4 months ago

1.0.0-alpha.5

4 months ago

1.0.0-alpha.4

4 months ago

1.0.0-alpha.3

4 months ago

1.0.0-alpha.1

4 months ago

0.17.4

7 months ago

0.17.2

1 year ago

0.17.3

1 year ago

0.17.1

1 year ago

0.17.0

3 years ago

0.16.3

3 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

6 years ago

0.13.0

6 years ago

0.12.2

6 years ago

0.12.1

6 years ago

0.12.0

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.3

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.23

7 years ago

0.9.0-beta.2

8 years ago

0.9.0-beta.1

8 years ago

0.8.22

8 years ago

0.8.21

8 years ago

0.8.20

8 years ago

0.8.19

8 years ago

0.8.18

8 years ago

0.8.17

8 years ago

0.8.16

8 years ago

0.8.15

8 years ago

0.8.14

8 years ago

0.8.13

8 years ago

0.8.12

8 years ago

0.8.11

8 years ago

0.8.10

8 years ago

0.8.9

8 years ago

0.8.8

8 years ago

0.8.7

8 years ago

0.8.6

8 years ago

0.8.5

8 years ago

0.8.4

8 years ago

0.8.3

8 years ago

0.8.2

9 years ago

0.8.1

9 years ago

0.8.0

9 years ago

0.7.28

9 years ago

0.7.27

9 years ago

0.7.26

9 years ago

0.7.25

9 years ago

0.7.24

9 years ago

0.7.23

9 years ago

0.7.21

9 years ago

0.7.20

9 years ago

0.7.19

9 years ago

0.7.18

9 years ago

0.7.17

9 years ago

0.7.16

9 years ago

0.7.15

9 years ago

0.7.14

9 years ago

0.7.13

9 years ago

0.7.12

9 years ago

0.7.11

9 years ago

0.7.10

9 years ago

0.7.9

9 years ago

0.7.8

9 years ago

0.7.7

9 years ago

0.7.6

9 years ago

0.7.5

9 years ago

0.7.4

9 years ago

0.7.3

9 years ago

0.7.2

9 years ago

0.7.1

9 years ago

0.7.0

9 years ago

0.6.10

9 years ago

0.6.9

9 years ago

0.6.8

9 years ago

0.6.7

9 years ago

0.6.6

9 years ago

0.6.5

9 years ago

0.6.4

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.12

9 years ago

0.5.11

9 years ago

0.5.10

9 years ago

0.5.9

9 years ago

0.5.8

9 years ago

0.5.7

9 years ago

0.5.6

9 years ago

0.5.5

9 years ago

0.5.4

9 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.11

10 years ago

0.3.10

10 years ago

0.3.9

10 years ago

0.3.8

10 years ago

0.3.7

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago