Notion Tip: Use this page to describe your approach to interviewing product candidates.
HTTP 常见状态码
- 200 成功
- 301 永久重定向(配合 location,浏览器自动处理)
- 302 临时重定向(配合 location,浏览器自动处理)
- 304 资源未被修改
- 403 没有权限
- 404 资源未找到
- 500 服务器错误
- 504 网关超时
HTTP methods
传统的 methods
get
获取服务端的数据
post
向服务器提交数据
现在的 methods
get
获取数据
post
新建数据
patch/put
更新数据
delete
删除数据
Restful API
一种 API 设计方法
传统 API 设计: 把每个 url 当成一个功能
Restful API: 把每个 url 当作一个唯一的资源
如何设计
- 尽量不用 url 参数
传统 API 设计: /api/list?pageIndex=2
Restful API 设计: /api/list/2
- 用 method 表示操作类型
传统 API 设计 post 请求/api/create-blog
get 请求/api/get-blog?id=100
Restful API post 请求/api/blog
patch 请求/api/blog/100
get 请求/api/blog/100