JSONPlaceholder posts
API 文档
官网地址 https://jsonplaceholder.typicode.com/
介绍
JSONPlaceholder 是一个免费的模拟 RESTful API。本文档详细描述了如何与 posts
资源进行交互。
基本信息
- Base URL:
https://jsonplaceholder.typicode.com
- Media Type:
application/json
错误码
HTTP 状态码 | 描述 |
---|---|
400 | 请求的数据格式错误 |
404 | 资源未找到 |
500 | 服务器内部错误 |
API 接口描述
1. 获取所有 posts
请求
- Method:
GET
- URL:
/posts
- Headers:
- Accept:
application/json
- Accept:
响应
- 成功响应:
- Code:
200 OK
- Content-Type:
application/json
- Body:
json[ { "userId": 1, "id": 1, "title": "...", "body": "..." }, ... ]
- Code:
2. 获取单个 post
请求
- Method:
GET
- URL:
/posts/:id
- Headers:
- Accept:
application/json
- Accept:
响应
- 成功响应:
- Code:
200 OK
- Content-Type:
application/json
- Body:
json{ "userId": 1, "id": 1, "title": "...", "body": "..." }
- Code:
3. 创建一个新的 post
请求
- Method:
POST
- URL:
/posts
- Headers:
- Accept:
application/json
- Content-Type:
application/json
- Accept:
- Body:json
{ "title": "[string]", "body": "[string]", "userId": [integer] }
响应
- 成功响应:
- Code:
201 Created
- Content-Type:
application/json
- Body:
json{ "title": "...", "body": "...", "userId": ..., "id": ... }
- Code:
4. 更新一个 post
请求
- Method:
PUT
- URL:
/posts/:id
- Headers:
- Accept:
application/json
- Content-Type:
application/json
- Accept:
- Body:json
{ "id": [integer], "title": "[string]", "body": "[string]", "userId": [integer] }
响应
- 成功响应:
- Code:
200 OK
- Content-Type:
application/json
- Body:
json{ "title": "...", "body": "...", "userId": ..., "id": ... }
- Code:
5. 删除一个 post
请求
- Method:
DELETE
- URL:
/posts/:id
- Headers:
- Accept:
application/json
- Accept:
响应
- 成功响应:
- Code:
200 OK
- Content-Type:
application/json
- Body:
{}
- Code:
6. 分页查询
请求
- Method:
GET
- URL:
/posts
- Headers:
- Accept:
application/json
- Accept:
- Query Parameters:
_limit=[integer]
,每页显示的数量_start=[integer]
,从哪个post
开始
响应
- 成功响应:
- Code:
200 OK
- Content-Type:
application/json
- Body:
json[ ... ]
- Code:
示例
获取前 5 个
posts
:GET https://jsonplaceholder.typicode.com/posts?_limit=5
获取 ID 为 3 的
post
:GET https://jsonplaceholder.typicode.com/posts/3
更新 ID 为 4 的
post
:PUT https://sonplaceholder.typicode.com/posts/4