Skip to content

Instantly share code, notes, and snippets.

@shady-robot
Created December 5, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shady-robot/b3e6dc3d5c06bada8b635335dc28be0b to your computer and use it in GitHub Desktop.
Save shady-robot/b3e6dc3d5c06bada8b635335dc28be0b to your computer and use it in GitHub Desktop.
在发送一个REST API请求时,根据应用的场景,针对相同的资源,可能会期待不同的返回形式。
Rest API应具备完整的内容协商能力
通过在header里面设置 Accept:告诉WEB服务器自己接收的内容类型,内容类型中的先后次序表示客户端接收的先后次序。 */* 表示任何类型,type/* 表示该text/html,application/json
请求不支持的格式:415 Unsupported Media Type
--->
(1). 返回内容格式指定
http://gym.api.ruizhutech.com/activities/251/entrances/?format=json
(2). 通过在header里面指定
http://gym.api.ruizhutech.com/activities/251/entrances/
BrowserableAPI的好处:
方便进行相关的测试,
@shady-robot
Copy link
Author

shady-robot commented Dec 5, 2016

层次化的系统表示组件无法了解它与之交互的中间层以外的组件。通过将系统知识限制在但各层,可以限制整个系统的复杂性,促进了底层的独立性。

,客户端不再和 URI 紧耦合。在第 1 级或者第 2 级的应用里面,客户端都需要知道资源使用的 URI 模版(如 /orders/{id}),然后要操作什么样的资源就生成什么样的 URI。超媒体客户端只知道入口 URI,之后的每一个 URI 都是通过超链接获得的。

Stackoverflow: http://stackoverflow.com/questions/671118/what-exactly-is-restful-programming

map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

expires $expires;

https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/08.3.md
image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment