{"id":19692206,"url":"https://github.com/robeio/robe-json-server","last_synced_at":"2025-07-04T11:39:05.810Z","repository":{"id":78846767,"uuid":"67507823","full_name":"robeio/robe-json-server","owner":"robeio","description":"Robe Json Server","archived":false,"fork":false,"pushed_at":"2017-01-03T11:32:00.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-09T12:22:03.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robeio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-06T12:51:21.000Z","updated_at":"2016-09-06T12:53:39.000Z","dependencies_parsed_at":"2023-06-09T14:15:17.492Z","dependency_job_id":null,"html_url":"https://github.com/robeio/robe-json-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robeio/robe-json-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robeio%2Frobe-json-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robeio%2Frobe-json-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robeio%2Frobe-json-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robeio%2Frobe-json-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robeio","download_url":"https://codeload.github.com/robeio/robe-json-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robeio%2Frobe-json-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263503230,"owners_count":23476732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T19:12:38.227Z","updated_at":"2025-07-04T11:39:05.780Z","avatar_url":"https://github.com/robeio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Server [![](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/typicode/json-server?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nGet a full fake REST API with __zero coding__ in __less than 30 seconds__ (seriously)\n\nCreated with \u003c3 for front-end developers who need a quick back-end for prototyping and mocking.\n\n* [Egghead.io free video tutorial - Creating demo APIs with json-server](https://egghead.io/lessons/nodejs-creating-demo-apis-with-json-server)\n* [JSONPlaceholder - Live running version](http://jsonplaceholder.typicode.com)\n\nSee also:\n* :hotel: [hotel - Get local domains in seconds](https://github.com/typicode/hotel)\n* :dog: [husky - Git hooks made easy](https://github.com/typicode/husky)\n\n## Example\n\nCreate a `db.json` file\n\n```json\n{\n  \"posts\": [\n    { \"id\": 1, \"title\": \"json-server\", \"author\": \"typicode\" }\n  ],\n  \"comments\": [\n    { \"id\": 1, \"body\": \"some comment\", \"postId\": 1 }\n  ],\n  \"profile\": { \"name\": \"typicode\" }\n}\n```\n\nStart JSON Server\n\n```bash\n$ json-server --watch db.json\n```\n\nNow if you go to [http://localhost:3000/posts/1](), you'll get\n\n```json\n{ \"id\": 1, \"title\": \"json-server\", \"author\": \"typicode\" }\n```\n\nAlso when doing requests, its good to know that\n- If you make POST, PUT, PATCH or DELETE requests, changes will be automatically and safely saved to `db.json` using [lowdb](https://github.com/typicode/lowdb).\n- Your request body JSON should be object enclosed, just like the GET output. (for example `{\"name\": \"Foobar\"}`)\n- Id values are not mutable. Any `id` value in the body of your PUT or PATCH request wil be ignored. Only a value set in a POST request wil be respected, but only if not already taken.\n- A POST, PUT or PATCH request should include a `Content-Type: application/json` header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data.\n\n## Install\n\n```bash\n$ npm install -g json-server\n```\n\n## Routes\n\nBased on the previous `db.json` file, here are all the default routes. You can also add [other routes](#add-routes) using `--routes`.\n\n### Plural routes\n\n```\nGET    /posts\nGET    /posts/1\nPOST   /posts\nPUT    /posts/1\nPATCH  /posts/1\nDELETE /posts/1\n```\n\n### Singular routes\n\n```\nGET    /profile\nPOST   /profile\nPUT    /profile\nPATCH  /profile\n```\n\n### Filter\n\nUse `.` to access deep properties\n\n```\nGET /posts?title=json-server\u0026author=typicode\nGET /posts?id=1\u0026id=2\nGET /comments?author.name=typicode\n```\n\n### Slice\n\nAdd `_start` and `_end` or `_limit` (an `X-Total-Count` header is included in the response)\n\n```\nGET /posts?_start=20\u0026_end=30\nGET /posts/1/comments?_start=20\u0026_end=30\nGET /posts/1/comments?_start=20\u0026_limit=10\n```\n\n### Sort\n\nAdd `_sort` and `_order` (ascending order by default)\n\n```\nGET /posts?_sort=views\u0026_order=DESC\nGET /posts/1/comments?_sort=votes\u0026_order=ASC\n```\n\n### Operators\n\nAdd `_gte` or `_lte` for getting a range\n\n```\nGET /posts?views_gte=10\u0026views_lte=20\n```\n\nAdd `_ne` to exclude a value\n\n```\nGET /posts?id_ne=1\n```\n\nAdd `_like` to filter (RegExp supported)\n\n```\nGET /posts?title_like=server\n```\n\n### Full-text search\n\nAdd `q`\n\n```\nGET /posts?q=internet\n```\n\n### Relationships\n\nTo include children resources, add `_embed`\n\n```\nGET /posts?_embed=comments\nGET /posts/1?_embed=comments\n```\n\nTo include parent resource, add `_expand`\n\n```\nGET /comments?_expand=post\nGET /comments/1?_expand=post\n```\n\nTo get or create nested resources (by default one level, [add routes](#add-routes) for more)\n\n```\nGET  /posts/1/comments\nPOST /posts/1/comments\n```\n\n### Database\n\n```\nGET /db\n```\n\n### Homepage\n\nReturns default index file or serves `./public` directory\n\n```\nGET /\n```\n\n## Extras\n\n### Static file server\n\nYou can use JSON Server to serve your HTML, JS and CSS, simply create a `./public` directory\nor use `--static`.\n\n```bash\nmkdir public\necho 'hello world' \u003e public/index.html\njson-server db.json\n```\n\n```bash\njson-server db.json --static ./static\n```\n\n### Alternative port\n\nYou can start JSON Server on other ports with the `--port` flag:\n\n```bash\n$ json-server --watch db.json --port 3004\n```\n\n### Access from anywhere\n\nYou can access your fake API from anywhere using CORS and JSONP.\n\n### Remote schema\n\nYou can load remote schemas.\n\n```bash\n$ json-server http://example.com/file.json\n$ json-server http://jsonplaceholder.typicode.com/db\n```\n\n### Generate random data\n\nUsing JS instead of a JSON file, you can create data programmatically.\n\n```javascript\n// index.js\nmodule.exports = function() {\n  var data = { users: [] }\n  // Create 1000 users\n  for (var i = 0; i \u003c 1000; i++) {\n    data.users.push({ id: i, name: 'user' + i })\n  }\n  return data\n}\n```\n\n```bash\n$ json-server index.js\n```\n\n__Tip__ use modules like [faker](https://github.com/Marak/faker.js), [casual](https://github.com/boo1ean/casual) or [chance](https://github.com/victorquinn/chancejs).\n\n### Add routes\n\nCreate a `routes.json` file. Pay attention to start every route with /.\n\n```json\n{\n  \"/api/\": \"/\",\n  \"/blog/:resource/:id/show\": \"/:resource/:id\"\n}\n```\n\nStart JSON Server with `--routes` option.\n\n```bash\njson-server db.json --routes routes.json\n```\n\nNow you can access resources using additional routes.\n\n```bash\n/api/posts\n/api/posts/1\n/blog/posts/1/show\n```\n\n### Add middlewares\n\nYou can add your middlewares from the CLI using `--middlewares` option:\n\n```js\n// first.js\nmodule.exports = function (req, res, next) {\n  res.Header('X-Hello', 'World')\n}\n```\n\n```bash\njson-server db.json --middlewares ./hello.js\njson-server db.json --middlewares ./first.js ./second.js\n```\n\n### CLI usage\n\n```\njson-server [options] \u003csource\u003e\n\nOptions:\n  --config, -c       Path to config file           [default: \"json-server.json\"]\n  --port, -p         Set port                                    [default: 3000]\n  --host, -H         Set host                               [default: \"0.0.0.0\"]\n  --watch, -w        Watch file(s)                                     [boolean]\n  --routes, -r       Path to routes file\n  --middlewares, -m  Paths to middleware files                           [array]\n  --static, -s       Set static files directory\n  --read-only, --ro  Allow only GET requests                           [boolean]\n  --no-cors, --nc    Disable Cross-Origin Resource Sharing             [boolean]\n  --no-gzip, --ng    Disable GZIP Content-Encoding                     [boolean]\n  --snapshots, -S    Set snapshots directory                      [default: \".\"]\n  --delay, -d        Add delay to responses (ms)\n  --id, -i           Set database id property (e.g. _id)         [default: \"id\"]\n  --quiet, -q        Suppress log messages from output                 [boolean]\n  --help, -h         Show help                                         [boolean]\n  --version, -v      Show version number                               [boolean]\n\nExamples:\n  json-server db.json\n  json-server file.js\n  json-server http://example.com/db.json\n\nhttps://github.com/typicode/json-server\n```\n\nYou can also set options in a `json-server.json` configuration file.\n\n```json\n{\n  \"port\": 3000\n}\n```\n\n### Module\n\nIf you need to add authentication, validation, or __any behavior__, you can use the project as a module in combination with other Express middlewares.\n\n#### Simple example\n\n```js\n// server.js\nvar jsonServer = require('json-server')\nvar server = jsonServer.create()\nvar router = jsonServer.router('db.json')\nvar middlewares = jsonServer.defaults()\n\nserver.use(middlewares)\nserver.use(router)\nserver.listen(3000, function () {\n  console.log('JSON Server is running')\n})\n```\n\n```sh\n$ node server.js\n```\n\nFor an in-memory database, you can pass an object to `jsonServer.router()`.\nPlease note also that `jsonServer.router()` can be used in existing Express projects.\n\n#### Custom routes example\n\nLet's say you want a route that echoes query parameters and another one that set a timestamp on every resource created.\n\n```js\nvar jsonServer = require('json-server')\nvar server = jsonServer.create()\nvar router = jsonServer.router('db.json')\nvar middlewares = jsonServer.defaults()\n\n// Set default middlewares (logger, static, cors and no-cache)\nserver.use(middlewares)\n\n// Add custom routes before JSON Server router\nserver.get('/echo', function (req, res) {\n  res.jsonp(req.query)\n})\n\nserver.use(function (req, res, next) {\n  if (req.method === 'POST') {\n    req.body.createdAt = Date.now()\n  }\n  // Continue to JSON Server router\n  next()\n})\n\n// Use default router\nserver.use(router)\nserver.listen(3000, function () {\n  console.log('JSON Server is running')\n})\n```\n\n#### Access control example\n\n```js\nvar jsonServer = require('json-server')\nvar server = jsonServer.create()\nvar router = jsonServer.router('db.json')\nvar middlewares = jsonServer.defaults()\n\nserver.use(middlewares)\nserver.use(function (req, res, next) {\n if (isAuthorized(req)) { // add your authorization logic here\n   next() // continue to JSON Server router\n } else {\n   res.sendStatus(401)\n }\n})\nserver.use(router)\nserver.listen(3000, function () {\n  console.log('JSON Server is running')\n})\n```\n\n#### Custom output example\n\nTo modify responses, overwrite `router.render` method:\n\n```javascript\n// In this example, returned resources will be wrapped in a body property\nrouter.render = function (req, res) {\n  res.jsonp({\n   body: res.locals.data\n  })\n}\n```\n\n#### Rewriter example\n\nTo add rewrite rules, use `jsonServer.rewriter()`:\n\n```javascript\n// Add this before server.use(router)\nserver.use(jsonServer.rewriter({\n  '/api/': '/',\n  '/blog/:resource/:id/show': '/:resource/:id'\n}))\n```\n\n#### Mounting JSON Server on another endpoint example\n\nAlternatively, you can also mount the router on `/api`.\n\n```javascript\nserver.use('/api', router)\n```\n\n### Deployment\n\nYou can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholder.typicode.com) is an online fake API powered by JSON Server and running on Heroku.\n\n## Links\n\n### Video\n\n* [Creating Demo APIs with json-server on egghead.io](https://egghead.io/lessons/nodejs-creating-demo-apis-with-json-server)\n\n### Articles\n\n* [Node Module Of The Week - json-server](http://nmotw.in/json-server/)\n* [Mock up your REST API with JSON Server](http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/)\n* [ng-admin: Add an AngularJS admin GUI to any RESTful API](http://marmelab.com/blog/2014/09/15/easy-backend-for-your-restful-api.html)\n* [Fast prototyping using Restangular and Json-server](http://glebbahmutov.com/blog/fast-prototyping-using-restangular-and-json-server/)\n* [Create a Mock REST API in Seconds for Prototyping your Frontend](https://coligo.io/create-mock-rest-api-with-json-server/)\n\n### Third-party tools\n\n* [Grunt JSON Server](https://github.com/tfiwm/grunt-json-server)\n* [Docker JSON Server](https://github.com/clue/docker-json-server)\n* [JSON Server GUI](https://github.com/naholyr/json-server-gui)\n* [JSON file generator](https://github.com/dfsq/json-server-init)\n\n## License\n\nMIT - [Typicode](https://github.com/typicode)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobeio%2Frobe-json-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobeio%2Frobe-json-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobeio%2Frobe-json-server/lists"}