月度归档:2015年09月

API自动化测试利器——Postman

自从开始做API开发之后,我就在寻找合适的API测试工具。一开始不是很想用Chrome扩展,用的WizTools的工具,后来试过一次Postman之后就停不下来了,还买了付费的Jetpacks。推出Team Sync Beta之后我又把这个工具推广给团队,作为API文档使用。看到中文网络上关于这个工具的文章并不多,于是决定写一篇小文介绍一下。

一、基本功能

Postman的功能在文档中有介绍。不过文档略啰嗦,这里简单介绍一下主界面,入门功能就都提到了。

继续阅读

PHP:设置Location导致状态码被修改为302

最近在试着做RESTful API,学了很多平时用不到的HTTP知识。在一个API上,我想用409 Conflict表示要创建的资源已经存在。这是一个挺冷门的状态码,在B/S结构中基本上用不到。RFC 2616对它的解释是:

409 Conflict

The request could not be completed due to a conflict with the current
state of the resource. This code is only allowed in situations where
it is expected that the user might be able to resolve the conflict and
resubmit the request. The response body SHOULD include enough
information for the user to recognize the source of the conflict.
Ideally, the response entity would include enough information for the
user or user agent to fix the problem; however, that might not be
possible and is not required.

《RESTful Web APIs》这本书在409 Conflict的解释中写到:

响应报头:如果该冲突是由于某些其他资源的存在(比如,客户端尝试创建的某个特定的资源已经存在了)而造成的话,那么Location报头应该链接到该资源的URL:也就是说,冲突的来源。

继续阅读