Mock

JSON Server

JSON-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously)

安装 JSON Server

$ npm install -g json-server
1

创建 db.json 文件

{
  "posts": [{ "id": 1, "title": "json-server", "author": "typicode" }],
  "comments": [{ "id": 1, "body": "some comment", "postId": 1 }],
  "profile": { "name": "typicode" }
}
1
2
3
4
5

启动 JSON Server

$ json-server --watch db.json
1
  • --port 8080: 修改监听端口,默认 3000 端口

访问 http://localhost:3000/posts/1, 你可以得到以下数据

{ "id": 1, "title": "json-server", "author": "typicode" }
1

REST Client

vscode 插件: REST Client

Content-Type

Content-Type: application/json
Content-Type: application/xml
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Type: image/png
Content-Type: application/x-www-form-urlencoded
1
2
3
4
5

Restful

@domain = http://localhost:3001

###
GET @domain
    ?page=2
    &pageSize=10

###
POST {{domain}}/notes HTTP/1.1
content-type: application/json
Authorization: token xxx

{
  "id": 9
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

GraphQL

POST https://api.github.com/graphql
Content-Type: application/json
Authorization: Bearer xxx
X-REQUEST-TYPE: GraphQL

query ($name: String!, $owner: String!) {
  repository(name: $name, owner: $owner) {
    name
    fullName: nameWithOwner
    description
    diskUsage
    forkCount
    stargazers(first: 5) {
        totalCount
        nodes {
            login
            name
        }
    }
    watchers {
        totalCount
    }
  }
}

{
    "name": "vscode-restclient",
    "owner": "Huachao"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
上次更新: 9/26/2019, 1:39:25 AM