RESTful Web Services Part 2 - Characteristics

来源:互联网 发布:大数据赚钱吗 编辑:程序博客网 时间:2024/05/23 19:19
1. Resources

    A resource is a thing that:

  • is unique (i.e., can be identified uniquely)
  • has at least one representation
  • has one or more attributes beyond ID
  • has a potential schema, or definition
  • can provide context, and
  • is reachable within the addressable universe

    A resource can be practically anything:
  • A blog post
  • A collection of blog posts
  • An image
  • A user
  • Map coordinates
  • A bank transaction
  • Search results
  • Documents
  • People
  • Places
  • Abstract Concepts (e.g. processes,transactions)

    A resource can be explored to:
  • Web Side
  • Resume
  • Aircraft
  • A Song
  • An Employee
  • A Transaction

    Not Resource* - Even these could be resources in the right context, but you have to stretch some to find it:

  • Mailing Address
  • $32.76
  • A Gallon of Gasoline
  • Love

2. Representations

    A representation is a description of a resource that is used for some computational purpose.  Representations can be thought of as models of the resource is question, and as is the case with any modeling, a given resource may have any number of distinct representations.

  • A Kitten
  • Some Text
  • Name:Bob
  • Breed:Tabby
  • ……
  • A Picture/A Drawing/A Haiku/A BlogPost
  • HTML
    • <!DOCTYPE html>
    • <html lang=“en”></html>
  • Video

3. Representational State Transfer
  • A representation shows a reflection of the state of a given resource in a given form
  • This “representational state”collapses to the resource description itself when the resource is static, but will change if the resource itself changes
  • The transfer of this representational state between nodes in the network is the fundamental operation of the web

4. Addressability

    Every resource has at least one URI; every URI points to a resource.
  • http://example.com/entities/2012/02/restful-web-services
  • http://example.com/tags/awesome
  • http://example.com

5. Idempotency

    Being able to perform an operation multiple times without changing theresult after the initial operation


6. Connectedness
  • Resources Link to Each Other
  • Connectedness
    • <?xml version=“1.0” encoding=“UTF-8” ?>
    • <resource xmlns=http://example.com/ns/resource >
      • <content>…</content>
      • <nextResource href=http://example.com/resource/3/>
      • <prevResource href=http://example.com/resource/1/>
    • </resource>
    • <link rel=“alternate”type=“application/atom+xml” href=http://example.com/resource/2.atom/>
  • HATEOAS - Hypermedia as the Engine of Application State

7. Statelessness
  • HTTP Is Stateless - Every Request Happens in Isolation
  • State Machine
  • Resource State – Server-Side
  • Application State – Client-Side
  • Transferring Sate – Every HTTPrequest transfers state between the application and the requested resource
    • Resource-> Application e.g. GET
    • Resource<- Application e.g. PUT
  • Representation State Transfer


0 0
原创粉丝点击