Skip to content

Commit 104c36f

Browse files
committed
README.md
1 parent 3939bf6 commit 104c36f

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

README.md

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
在不需要书写代码的情况下,获取一个完整的假数据 REAST API 只需要 30 秒(我是认真的)。
66

7+
如果同时使用 [Postman](http://getpostman.com/) 一款功能强大的网页调试与模拟发送网页 HTTP 请求的 Chrome 插件,则真真的能实现前后端完全分离。
8+
79
## 基础环境:
810

911
- [Node.js](https://nodejs.org)
1012
- npm
13+
- Chrome 插件 Postman
1114

1215
### 查看环境:
1316

@@ -18,8 +21,60 @@ $ npm -v
1821
2.1.18
1922
```
2023

21-
## 实例
24+
## `JSON-server` 实例
25+
2226
1.创建`db.json`文件
27+
```json
28+
{
29+
"posts": [
30+
{
31+
"id": 1,
32+
"title": "json-server",
33+
"author": "typicode"
34+
},
35+
{
36+
"id": 2,
37+
"title": "json-server",
38+
"author": "typicode2"
39+
},
40+
{
41+
"id": 3,
42+
"title": "json-server",
43+
"author": "typicode3"
44+
},
45+
{
46+
"id": 4,
47+
"title": "fy-server",
48+
"author": "typicode3"
49+
},
50+
{
51+
"id": 5,
52+
"title": "fy-server",
53+
"author": "typicode3"
54+
}
55+
],
56+
"comments": [
57+
{
58+
"id": 1,
59+
"body": "some comment",
60+
"postId": 1
61+
},
62+
{
63+
"id": 2,
64+
"body": "some comment",
65+
"postId": 1
66+
},
67+
{
68+
"id": 3,
69+
"body": "some comment",
70+
"postId": 2
71+
}
72+
],
73+
"profile": {
74+
"name": "typicode"
75+
}
76+
}
77+
```
2378

2479
2.安装`json-server`
2580

@@ -35,11 +90,11 @@ json-server --watch db.json
3590

3691
4.访问数据
3792

38-
http://localhost:3000/
93+
[http://localhost:3000/](http://localhost:3000/)
3994

40-
## 路由
95+
### JSON-server 路由
4196

42-
### 过滤器(Filter)
97+
#### 过滤器(Filter)
4398

4499
使用`.`访问深层数据
45100

@@ -49,34 +104,34 @@ GET /posts?id=1&id=2
49104
GET /comments?author.name=typicode
50105
```
51106

52-
### 数据分页(Slice) `_start` `_end` `_limit`
107+
#### 数据分页(Slice) `_start` `_end` `_limit`
53108

54109
```
55110
GET /posts?_start=20&_end=30
56111
GET /posts/1/comments?_start=20&_end=30
57112
GET /posts/1/comments?_start=20&_limit=10
58113
```
59114

60-
### 分类(Sort) `_sort` `_order`(DESC ASC)
115+
#### 分类(Sort) `_sort` `_order`(DESC ASC)
61116

62117
```
63118
GET /posts?_sort=views&_order=DESC
64119
GET /posts/1/comments?_sort=votes&_order=ASC
65120
```
66121

67-
### 范围(Range) `_gte` `_lte`
122+
#### 范围(Range) `_gte` `_lte`
68123

69124
```
70125
GET /posts?views_gte=10&views_lte=20
71126
```
72127

73-
### 搜索(Full-text search) `q`
128+
#### 搜索(Full-text search) `q`
74129

75130
```
76131
GET /posts?q=internet
77132
```
78133

79-
### 关系数据(Relationships) `_embed ` `_expand` `/`
134+
#### 关系数据(Relationships) `_embed ` `_expand` `/`
80135

81136
`_embed` 包含子类数据
82137
`_expand` 包含父类数据
@@ -95,9 +150,13 @@ GET /comments/1?_expand=post
95150
GET /posts/1/comments
96151
```
97152

98-
### 获取所有假数据
153+
#### 获取所有假数据
99154

100155
```
101156
GET /db
102157
```
103-
[lowdb](https://github.com/typicode/lowdb)
158+
159+
160+
### JSON-server 路由配置
161+
162+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"express": "^4.9.5",
1717
"got": "^3.3.0",
1818
"lodash": "^3.9.2",
19-
"lowdb": "^0.10.0",
19+
"lowdb": "^0.10.2",
2020
"method-override": "^2.1.2",
2121
"morgan": "^1.3.1",
2222
"node-uuid": "^1.4.2",

0 commit comments

Comments
 (0)