关闭

关于RESTful

标签: restfulweb服务
195人阅读 评论(0) 收藏 举报
分类:

最近纠结于RESTful的规范,翻了一下wiki,发现已经说的很好了,原文关于web服务的部分如下:


原文链接:https://en.wikipedia.org/wiki/Representational_state_transfer#CITEREFFielding2000

Applied to web services

Web service APIs that adhere to the REST architectural constraints are called RESTful APIs. HTTP-based RESTful APIs are defined with these aspects:

  • base URI, such as http://example.com/resources/
  • an Internet media type for the data. This is often JSON but can be any other valid Internet media type (e.g., XML, Atom, microformats, images, etc.)
  • standard HTTP methods (e.g., GET, PUT, POST, or DELETE)
  • hypertext links to reference state
  • hypertext links to reference-related resources[9]

Example[edit]

The following table shows the HTTP methods that are typically used to implement a RESTful API:

RESTful API HTTP methods
Resource GET PUT POST DELETE
Collection URI, such ashttp://api.example.com/resources/ List the URIs and perhaps other details of the collection's members. Replace the entire collection with another collection. Create a new entry in the collection. The new entry's URI is assigned automatically and is usually returned by the operation.[10] Delete the entire collection.
Element URI, such ashttp://api.example.com/resources/item17 Retrieve a representation of the addressed member of the collection, expressed in an appropriate Internet media type. Replace the addressed member of the collection, or if it does not exist, create it. Not generally used. Treat the addressed member as a collection in its own right and create a new entry in it.[10] Delete the addressed member of the collection.

The PUT and DELETE methods are referred to as idempotent, meaning that the operation will produce the same result no matter how many times it is repeated. The GET method is asafe method (or nullipotent), meaning that calling it produces no side-effects. In other words, retrieving or accessing a record does not change it.

Unlike SOAP-based web services, there is no "official" standard for RESTful web APIs.[11] This is because REST is an architectural style, while SOAP is a protocol. Even though REST is not a standard per se, most RESTful implementations make use of standards such as HTTPURIJSON, and XML.[11]

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:18685次
    • 积分:303
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:32篇
    • 译文:1篇
    • 评论:3条
    文章分类
    最新评论