Skip to content

Commit 96a455c

Browse files
committed
Update README.md
1 parent 7246259 commit 96a455c

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

README.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44

55
# JSON Server [![Build Status](https://travis-ci.org/typicode/json-server.svg)](https://travis-ci.org/typicode/json-server) [![NPM version](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server)
66

7-
Give it a JSON or JS seed file and it will serve it through REST routes.
7+
> Give it a JSON or JS file and it will serve it through REST routes.
88
99
Created with <3 for front-end developers who need a flexible back-end for quick prototyping and mocking.
1010

1111
_Powers [JSONPlaceholder](http://jsonplaceholder.typicode.com)_
1212

13-
## Examples
13+
## Usage
1414

15-
### Command line interface
15+
### CLI
16+
17+
Create a `db.json` file:
1618

1719
```javascript
18-
// db.json
1920
{
2021
"posts": [
2122
{ "id": 1, "body": "foo" }
2223
]
2324
}
2425
```
2526

26-
```bash
27-
$ json-server db.json
28-
$ curl -i http://localhost:3000/posts/1
29-
```
27+
Then run `json-server db.json` and go to `http://localhost:3000/posts/1`.
3028

31-
### Node module
29+
You should get `{ "id": 1, "body": "foo" }`.
30+
31+
### Module
3232

3333
```javascript
3434
var server = require('json-server');
@@ -40,24 +40,23 @@ server({
4040
}).listen(3000);
4141
```
4242

43-
You can find a running demo here: http://jsonplaceholder.typicode.com.
43+
__Tip__ You can mount json-server in Express apps.
4444

45-
## Why?
45+
## Features
4646

4747
* Lets you use plain JSON or simple JS file
4848
* Supports __GET__ but also __POST__, __PUT__, __DELETE__ and even __PATCH__ requests
4949
* Can be used from anywhere through __cross domain__ requests (JSONP or CORS)
5050
* Can load remote JSON files ([JSON Generator](http://www.json-generator.com/), ...)
5151
* Can be deployed on Nodejitsu, Heroku, ...
5252

53-
54-
## Installation
53+
## Install
5554

5655
```bash
5756
$ npm install -g json-server
5857
```
5958

60-
## CLI usage
59+
## CLI options
6160

6261
```bash
6362
json-server <source>
@@ -78,7 +77,7 @@ Options:
7877

7978
Here's 2 examples showing how to format JSON or JS seed file:
8079

81-
* __db.json__
80+
__JSON__
8281

8382
```javascript
8483
{
@@ -93,7 +92,7 @@ Here's 2 examples showing how to format JSON or JS seed file:
9392
}
9493
```
9594

96-
* __file.js__
95+
__JS__
9796

9897
```javascript
9998
module.exports = function() {
@@ -109,39 +108,41 @@ module.exports = function() {
109108

110109
JSON Server expects JS files to export a function that returns an object.
111110

112-
Seed files are useful if you need to programmaticaly create a lot of data.
111+
JS files are useful if you need to programmaticaly create a lot of data.
112+
113+
## Available routes
113114

114-
## Routes
115+
Let's say we have `posts`, here's the routes you can use.
115116

116117
```
117-
GET /:resource
118-
GET /:resource?filter=&filter=&
119-
GET /:parent/:parentId/:resource
120-
GET /:resource/:id
121-
POST /:resource
122-
PUT /:resource/:id
123-
PATCH /:resource/:id
124-
DEL /:resource/:id
118+
GET /posts
119+
GET /posts?title=jsonserver&author=typicode
120+
GET /posts/1/comments
121+
GET /posts/1
122+
POST /posts
123+
PUT /posts/1
124+
PATCH /posts/1
125+
DEL /posts/1
125126
```
126127

127128
To slice resources, add `_start` and `_end`.
128129

129130
```
130-
GET /:resource?_start=&_end=
131-
GET /:parent/:parentId/:resource?_start=&_end=
131+
GET /posts?_start=0&_end=10
132+
GET /posts/1/comments?_start=0&_end=10
132133
```
133134

134135
To sort resources, add `_sort` and `_order` (ascending order by default).
135136

136137
```
137-
GET /:resource?_sort=&_order=(ASC|DESC)
138-
GET /:parent/:parentId/:resource?_sort=&_order=(ASC|DESC)
138+
GET /posts?_sort=views&_order=DESC
139+
GET /posts/1/comments?_sort=votes&_order=ASC
139140
```
140141

141142
To make a full-text search on resources, add `q`.
142143

143144
```
144-
GET /:resource?q=
145+
GET /posts?q=internet
145146
```
146147

147148
Returns database.
@@ -150,13 +151,13 @@ Returns database.
150151
GET /db
151152
```
152153

153-
Returns default index file or content of ./public/index.html (useful if you need to set a custom home page).
154+
Returns default index file or content of `./public/index.html` (useful if you need to set a custom home page).
154155

155156
```
156157
GET /
157158
```
158159

159-
For routes usage examples, have a look at [JSONPlaceholder](https://github.com/typicode/jsonplaceholder)'s README.
160+
For more routes usage examples, have a look at [JSONPlaceholder](https://github.com/typicode/jsonplaceholder)'s README.
160161

161162
## Links
162163

0 commit comments

Comments
 (0)