1.0.0-alpha.23 • Published 1 month ago

json-server v1.0.0-alpha.23

Weekly downloads
157,280
License
SEE LICENSE IN ./...
Repository
-
Last release
1 month 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-newfoodhubfoodie_4foodorder-applicationflexmockfruit-apiparrot-clinpmpaquetesnuc-platform-expressnss-json-serverpipe-line-testingoptee_modalplato-dev-dependenciesplatfrom-expressplatform-expressreact-generator-screact-guma-authreact-starter-projectredux-some-storeredux-something-storerestful-api-for-easy-deploy-to-services-like-cyclicreact-shared-reduxgraphql-boilerplate-simpleservergenesis-uigroceriesdeliverygrunt-appverse-jsonservergrunt-json-serverpro-build-engineproyecto-nodequ4rtetqu4rtet-uiqcx-cliraml-serviceraml-serverprimerpaquetegrouparquickfoodsr2d2tablepratamo-servemobin-tagmobin-tagilizemock-rest-apimock-local-servermockingjay.jsmocker-server-climy-saul-appmy-test-app-1msw-servermts-mock-serverngx-do-api-gatewayngx-do-proxynodejannodejs2024node4jannode4jan24node77node99node_5jan_newfileorg-chart-newpadamnode17nodejsshristynorthwind-rest-servernpm-js-alveromerfarooq97-javascript-taskshappymockgulp-json-servergulp-json-srv
1.0.0-alpha.23

1 month ago

1.0.0-alpha.22

1 month ago

1.0.0-alpha.21

2 months ago

1.0.0-alpha.20

2 months ago

1.0.0-alpha.19

2 months ago

1.0.0-alpha.18

2 months ago

1.0.0-alpha.17

2 months ago

1.0.0-alpha.16

2 months ago

1.0.0-alpha.15

2 months ago

1.0.0-alpha.14

2 months ago

1.0.0-alpha.12

2 months ago

1.0.0-alpha.11

2 months ago

1.0.0-alpha.13

2 months ago

1.0.0-alpha.10

2 months ago

1.0.0-alpha.9

2 months ago

1.0.0-alpha.8

2 months ago

1.0.0-alpha.7

2 months ago

1.0.0-alpha.6

2 months ago

1.0.0-alpha.5

2 months ago

1.0.0-alpha.4

2 months ago

1.0.0-alpha.3

2 months ago

1.0.0-alpha.1

2 months ago

0.17.4

5 months ago

0.17.2

1 year ago

0.17.3

11 months ago

0.17.1

1 year ago

0.17.0

2 years ago

0.16.3

3 years ago

0.16.2

3 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.1

4 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

7 years ago

0.9.0-beta.1

7 years ago

0.8.22

7 years ago

0.8.21

7 years ago

0.8.20

7 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

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.28

8 years ago

0.7.27

8 years ago

0.7.26

8 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

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 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