1.0.0-beta.0 ā€¢ Published 19 days ago

json-server v1.0.0-beta.0

Weekly downloads
157,280
License
SEE LICENSE IN ./...
Repository
github
Last release
19 days ago

json-server

Node.js CI

!IMPORTANT Viewing beta v1 documentation ā€“ usable but expect breaking changes. For stable version, see here

šŸ‘‹ Hey! Using React, Vue or Astro? Check my new project MistCSS to write 50% less code.

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

Sponsorware

!NOTE This project uses the Fair Source License. Only organizations with 3+ users are kindly asked 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/.

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

Notable differences with v0.17

  • id is always a string and will be generated for you if missing
  • use _per_page with _page instead of _limitfor pagination
  • use Chrome's Network tab > throtling to delay requests instead of --delay CLI option
@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-newgigantic_sausagegraphql-boilerplate-simpleserverjsongrok-serverjunaid1jwt-json-serverkakashi.jsks-mockkyoul-paymacondo-mocklowservergulp-json-servergulp-json-srvgulp-json-srv-forkedgrunt-json-servergulp-server-iogroceriesdeliverygrunt-appverse-jsonserverhappymockhash8-platformheaderfilehieunv_iiotprotocolheatwaveshw-knowledge-management-json-serverinnov-boxjojo-mockjord_global_pickers_newjsbattle-mockserverjson-data-serverjslib-test-utilsjson20jsonserver-fake-authjsonplaceholderjsproxy-serverjson-server-sxtensionjson-serverless-libjson-server-extensionjson-server-mockyjson-server-routerjson-server-simplejs-demo-utilsice-react-uiimpaktapps-ui-buildersjson-nowjsdoc-json-livemarketplace-testbedmdn-desarrollodesotfwaremocker-server-climockingjay.jsmock-rest-apimobin-tagmobin-tagilizemock-local-servermo-servemessage-random-21ngx-do-proxyngx-do-api-gatewaymy-saul-appmy-test-app-1nb-mock-apimts-mock-serverneptunes-componentsng2-rest-appmsw-servermy-app_todonn-code-librarynode-js-lkm-training-ciphernodejan
1.0.0-beta.0

19 days ago

1.0.0-alpha.23

4 months ago

1.0.0-alpha.22

4 months ago

1.0.0-alpha.21

5 months ago

1.0.0-alpha.20

5 months ago

1.0.0-alpha.19

5 months ago

1.0.0-alpha.18

5 months ago

1.0.0-alpha.17

5 months ago

1.0.0-alpha.16

5 months ago

1.0.0-alpha.15

5 months ago

1.0.0-alpha.14

5 months ago

1.0.0-alpha.12

5 months ago

1.0.0-alpha.11

5 months ago

1.0.0-alpha.13

5 months ago

1.0.0-alpha.10

5 months ago

1.0.0-alpha.9

5 months ago

1.0.0-alpha.8

5 months ago

1.0.0-alpha.7

5 months ago

1.0.0-alpha.6

5 months ago

1.0.0-alpha.5

5 months ago

1.0.0-alpha.4

5 months ago

1.0.0-alpha.3

6 months ago

1.0.0-alpha.1

6 months ago

0.17.4

8 months ago

0.17.2

1 year ago

0.17.3

1 year ago

0.17.1

2 years ago

0.17.0

3 years ago

0.16.3

4 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

7 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

8 years ago

0.9.1

8 years ago

0.9.0

8 years ago

0.8.23

8 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

9 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

10 years ago

0.5.4

10 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

11 years ago

0.0.0

11 years ago