Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/typicode/json-server
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
https://github.com/typicode/json-server
Last synced: 11 days ago
JSON representation
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
- Host: GitHub
- URL: https://github.com/typicode/json-server
- Owner: typicode
- License: other
- Created: 2013-11-27T13:21:13.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T10:33:10.000Z (about 2 months ago)
- Last Synced: 2024-10-08T14:07:44.678Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.33 MB
- Stars: 72,699
- Watchers: 1,001
- Forks: 7,009
- Open Issues: 698
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- my-awesome-starred - json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- awesome-toolbox - JSON Server
- awesome - typicode/json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- awesome-nodejs-projects - JSON-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously). (Developers)
- awesome - json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- -awesome-nodejs-projects - JSON-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously). (Developers)
- awesome-nodejs-projects - JSON-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously). (Developers)
- my-awesome - typicode/json-server - 09 star:72.9k fork:7.0k Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- awesome-nodejs - json-server - Get a full fake REST API with zero coding in less than 30 seconds. ![](https://img.shields.io/github/stars/typicode/json-server.svg?style=social&label=Star) (Repository / HTTP)
- awesome-list - typicode/json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- awesome-rainmana - typicode/json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- awesome-json - JSON Server - Get a full fake REST API with zero coding in less than 30 seconds. (Databases)
- awesome-rest - json-server - Serve a REST API from fixture files using quick prototyping. (Testing / Mocking)
- awesome-github-star - json-server
- awesome - json-server
- awesome-devtools - json-server - A cool way to set up a local mock json api for use to mock a real API. (Command line - Linux / Learning resources)
- awesome-list - json-server
- awesome-nodejs - json-server - 指定 json 文件作为 api 的数据源,模拟服务端接口数据 (Uncategorized / Uncategorized)
- awesome-nodejs-projects - JSON-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously). (Developers)
- awesome-tools - **json-server** - 最佳 RESTful API Mock (在線使用)
- awesome-frontend-libraries - json-server
- awesome-ops - typicode/json-server - 11-27|2024-09-24 | 一款能够直接将 json 内容转成 REST API 接口的工具,你可以在日常开发中,通过该工具快速进行调试 | (终端命令行工具)
- awesome-starred - typicode/json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (others)
- jimsghstars - typicode/json-server - Get a full fake REST API with zero coding in less than 30 seconds (seriously) (JavaScript)
- StarryDivineSky - typicode/json-server
- awesome-nodejs - json-server - 在不到 30 秒的时间内获得具有零编码的完整伪造的 REST API。 ![](https://img.shields.io/github/stars/typicode/json-server.svg?style=social&label=Star) (GIT 仓库 / HTTP)
README
# json-server
[![Node.js CI](https://github.com/typicode/json-server/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/json-server/actions/workflows/node.js.yml)
> [!IMPORTANT]
> Viewing beta v1 documentation – usable but expect breaking changes. For stable version, see [here](https://github.com/typicode/json-server/tree/v0)👋 _Hey! Using React, Vue or Astro? Check my new project [MistCSS](https://github.com/typicode/mistcss) to write 50% less code._
## Install
```shell
npm install json-server
```## Usage
Create a `db.json` or `db.json5` file
```json
{
"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"
}
}
```View db.json5 example
```json5
{
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](https://github.com/json5/json5).
Pass it to JSON Server CLI
```shell
$ npx json-server db.json
```Get a REST API
```shell
$ curl http://localhost:3000/posts/1
{
"id": "1",
"title": "a title",
"views": 100
}
```Run `json-server --help` for a list of options
## Sponsors ✨
| Sponsors |
| :---: |
| |
| || Sponsors | |
| :---: | :---: |
| | |
| | |[Become a sponsor and have your company logo here](https://github.com/users/typicode/sponsorship)
## Sponsorware
> [!NOTE]
> This project uses the [Fair Source License](https://fair.io/). Only organizations with 3+ users are kindly asked to contribute a small amount through sponsorship [sponsor](https://github.com/sponsors/typicode) 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/](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 Server will serve its content in addition to the REST API.
You can also add custom directories using `-s/--static` option.
```sh
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 `_limit`for pagination
- use Chrome's `Network tab > throtling` to delay requests instead of `--delay` CLI option