接口规范
接口协议
http / https
接口域名
本机:http:localhost:8000/api/
线上:https:www.example.com/api/
接口版本
https:www.example.com/api/v{n}
https:www.example.com/api/v1 https:www.example.com/api/v1.1
接口路径
API具体网址 “终点:最后的路径部分”
restful 规范 : 资源 - 对应数据库表名/集合名称 | 名词s
扩展具体路径 / 占位参数
https:www.example.com/api/v1/users https:www.example.com/api/v1/articles/follow 关注作者的文章
接口过滤信息
https:www.example.com/api/v1/articles/follow?limit=20&offset=0 https:www.example.com/api/v1/articles?tag=htlm&limit=20&offset=0
接口传参数据
请求body : json数据传给服务器
指定数据类型:Content-Type : application/json
{ “user”:{ “username”:”wangwu”, “password”:”123456”, “email”:”wangwu@qq.com” } }
restful地址栏参数
https:www.example.com/api/v1/articles/2hs6483 别名参数 https:www.example.com/api/v1/goods/id 商品id参数
header 传参
Authorization Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpoYW5nc2FuIiwiZW1haWwiOiJ6aGFuZ3NhbkBxcS5jb20iLCJpYXQiOjE2NDE5NTUzMjJ9.OCPVefmoMCMHfY5X0vVNoS3Gv2Xqf8HSqKScIbs7thE
cookie 传参
接口请求方式
客户端 - 服务端 - 数据库
GET - GET - SELECT
POST - POST - CREAT
PUT - PUT - UPDATE
DELETE - DELETE -DELETE
接口响应数据
状态码 和 数据
200 / 201
400 / 401 / 403 / 404
500
{status:1,message:'条件查询获取文章成功',data:articles}
注意
blog-v1接口文档
base地址:http:localhost:8000/api/v1
用户模块
用户创建
- 接口描述
- 创建用户
- 请求地址 :
- /users
- 请求方式
- post
参数
- body | 参数名称 | 必选 | 类型 | 说明 | | —- | —- | —- | —- | | email | 是 | string | 邮箱 | | username | 是 | string | 用户名 | | password | 是 | string | 密码 |
返回值
- status : 1 成功 / 0 失败
{status:1,message:'条件查询获取文章成功',data:{username:'',bio:'',avatar:'',email:'',token:''}}
用户登录
- 接口描述
- 用户登录
- 请求地址 :
- /users/login
- 请求方式
- post
参数
- body | 参数名称 | 必选 | 类型 | 说明 | | —- | —- | —- | —- | | email | 是 | string | 邮箱 | | password | 是 | string | 密码 |
返回值
- status : 1 成功 / 0 失败
{status: 1,data: user.dataValues,message: "用户登录成功",}
