惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

博客园 - Terry Sun

Ubuntu安装Java7 SDK Postgres整理 解决createdb: could not connect to database postgres: FATAL: Peer authentication failed for user &quot;postgres&quot; 如何升级Nginx到最新稳定版 The remote name could not be resolved:&#39;maps.googleapis.com&#39; 的解决办法 关于Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005的解决办法 [iOS]黑色状态栏 圆角内容区 No connection could be made because the target machine actively refused it 127.0.0.1:808 的解决办法 Google Map V3--geocode与fitBounds方法的同步操作 ADO.NET Entity Framework--不再查询直接更新数据 安装SSL证书-解决导入证书时的ASN1 bad tag value met错误 解决 The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>) - Terry Sun &lt;转&gt;用HTML判断IE版本 关于Master Page的css和js文件引用问题 ASP.NET Mvc 2.0 - 2. 异步Controller执行流程时序图 [转载]ASP.NET 2.0 中的异步页 ASP.NET Mvc 2.0 - 1. Areas的创建与执行 深入分析 ASP.NET Mvc 1.0 – 4. 使用ModelBinder绑定Action的参数 深入分析 ASP.NET Mvc 1.0 – 3. Controller.Execute(Request)-ActionInvoker.InvokeAction()
RESTful架构API的设计误区
Terry Sun · 2012-12-11 · via 博客园 - Terry Sun

RESTful架构有一些典型的设计误区。

最常见的一种设计错误,就是URI包含动词。因为"资源"表示一种实体,所以应该是名词,URI不应该有动词,动词应该放在HTTP协议中。

举例来说,某个URI是/posts/show/1,其中show是动词,这个URI就设计错了,正确的写法应该是/posts/1,然后用GET方法表示show。

如果某些动作是HTTP动词表示不了的,你就应该把动作做成一种资源。比如网上汇款,从账户1向账户2汇款500元,错误的URI是:

  POST /accounts/1/transfer/500/to/2

正确的写法是把动词transfer改成名词transaction,资源不能是动词,但是可以是一种服务:

  POST /transaction HTTP/1.1
  Host: 127.0.0.1
  
  from=1&to=2&amount=500.00

另一个设计误区,就是在URI中加入版本号

  http://www.example.com/app/1.0/foo

  http://www.example.com/app/1.1/foo

  http://www.example.com/app/2.0/foo

因为不同的版本,可以理解成同一种资源的不同表现形式,所以应该采用同一个URI。版本号可以在HTTP请求头信息的Accept字段中进行区分(参见Versioning REST Services):

  Accept: vnd.example-com.foo+json; version=1.0

  Accept: vnd.example-com.foo+json; version=1.1

  Accept: vnd.example-com.foo+json; version=2.0

引用: