标签 Restfull 下的文章

Representational state transfer (REST)或者 RESTful
特点:结构清晰、符合标准、易于理解、扩展方便
REST这个词,是Roy Thomas Fielding在他2000年的博士论文中提出的。

什么是RESTful架构:

  1. 每一个URI代表一种资源;
  2. 客户端和服务器之间,传递这种资源的某种表现层;
  3. 客户端通过四个HTTP动词,对服务器端资源进行操作,实现"表现层状态转化"。

总结:

  • URL定位资源,用HTTP动词(GET,PUT,POST,DELETE,HEAD,OPTIONS)描述操作。
  • REST描述的是在网络中client和server的一种交互形式;
  • REST本身不实用,实用的是如何设计 RESTful API(REST风格的网络接口)
  • Server提供的RESTful API中,URL中只使用名词来指定资源,原则上不使用动词。
  • “资源”是REST架构或者说整个网络处理的核心

- 阅读剩余部分 -

Success Message

{
  "code":0,
  "data":any  // any type of result
}

Failed Message

{
  "code":1, // 1-9999  >1
  "message":"string",  // error message
  "detail":any  // any detail of error message
}

Http Status Code HTTP Status Code

20x success status

Usually only use 200.
I only used 200 for success.

30x Redirect

4xx Client Response, Usually caused by the client side.

  • 400 for parameters error message
  • 422 for error message in process

5xx Server Response, Usually caused by the server side.