Home Tags About

RESTful Web services: The basics

22 Jul 2012
web rest

一篇介绍 RESTfull 的文章,写的不错: RESTful Web services: The basics

比较认同里面的一些观点:

  • Use HTTP methods explicitly
  • Be stateless
  • Expose directory structure-like URIs
    • Hide the server-side scripting technology file extensions (.jsp, .php, .asp), if any, so you can port to something else without changing the URIs.
    • Keep everything lowercase.
    • Substitute spaces with hyphens or underscores (one or the other).
    • Avoid query strings as much as you can.
    • Instead of using the 404 Not Found code if the request URI is for a partial path, always provide a default page or resource as a response.

    URIs should also be static so that when the resource changes or the implementation of the service changes, the link stays the same. This allows bookmarking. It’s also important that the relationship between resources that’s encoded in the URIs remains independent of the way the relationships are represented where they are stored.

  • Transfer XML, JSON, or both