Json-Server库
guide
text
1pnpm add json-server本地启用
- 可以用json也可以用json5。
npx json-server db.json5
json
1{
2 // 博客
3 "posts": [
4 {
5 "id": "1",
6 "title": "a title",
7 "views": 100
8 },
9 {
10 "id": "2",
11 "title": "another",
12 "views": 200
13 }
14 ],
15 "comments": [
16 {
17 "id": "1",
18 "text": "a comment about post 1",
19 "postId": "1"
20 },
21 {
22 "id": "2",
23 "text": "another comment about post 1",
24 "postId": "1"
25 }
26 ],
27 "profile": {
28 "name": "typicode"
29 }
30}然后就在本地启动了一个数据库api
bash
1JSON Server started on PORT :3000
2Press CTRL-C to stop
3Watching db.json5...
4
5♡( ◡‿◡ )
6
7Index:
8http://localhost:3000/
9
10Static files:
11Serving ./public directory if it exists
12
13Endpoints:
14http://localhost:3000/posts
15http://localhost:3000/comments
16http://localhost:3000/profile
17