880 likes | 1.04k Vues
REST & .NET. James Crisp .NET Practice Lead ThoughtWorks Australia. James Crisp. The Web. *-ilities. Scalability. Recoverability & Reliability. Security. Discoverability. How to bring to Web services?. Tunneling. RPC URLs POX SOAP & WS-*. RE presentational S tate
E N D
REST & .NET James Crisp .NET Practice Lead ThoughtWorks Australia
How to bring to Web services?
Tunneling RPC URLs POX SOAP & WS-*
REpresentational State Transfer
“REST contributes ... the rationale behind the modern Web's software architecture...” -- Roy Fielding
Resources e.g. Person, Car, Post
Representations <person> <name>Bill Gates</name> <gender>m</gender> </person>
Addressability http://mysite.com/people/joe_citizen http://mysite.com/people/joe_citizen/friends
GET POST HEAD PUT DELETE OPTIONS Support
GET GET /people/joe_citizen HTTP/1.1 Host: mysite.com Accept: application/xml
Response 200 OK Content-Type: application/xml Last-Modified: 2008-1-1 15:00.. <person> <name>Joe Citizen</name> <age>42</age> <gender>m</gender> </person>
HEAD HEAD /people/joe_citizen HTTP/1.1 Host: mysite.com 200 OK Content-Type: application/xml Last-Modified: 2008-1-1 15:00.. ETag: a32daf15-b33da2a4d Response
POST POST /people HTTP/1.1 Content-Type: text/xml Host: mysite.com .... <person> <name>Tina Jones</name> <age>25</age> <gender>F</gender> </person>
Response 201 CREATED Location: /people/tina_jones (optionally with body)
PUT PUT /people/tina_jones HTTP/1.1 Content-Type: text/xml Host: mysite.com .... <person> <name>Tina Jones</name> <age>24</age> <gender>F</gender> </person>
Response 200 OK Location: /people/tina_jones (optionally with body)
DELETE DELETE /people/joe_citizen HTTP/1.1 Host: mysite.com 200 OK Content-Type: application/xml <admin:personDeleted> joe_citizen </admin:personDeleted> Response
OPTIONS OPTIONS /people HTTP/1.1 Host: mysite.com Response 200 OK Allowed: GET,HEAD,POST
2xx = All good 200 – OK 201 – Created
3xx = Redirect 301 – Moved permanently 307 – Temporary redirect304 – Not modified (ie, see cache)
4xx = Client error 400 – Bad request 401 – Unauthorized 403 – Forbidden 405 – Method not allowed 409 – Conflict
5xx = Server error 500 – Internal server error
Content-Type: text/html application/xml image/jpeg ....
WWW-Authenticate: Authorization:
Last-Modified: If-Modified-Since: ETag: If-None-Match:
URI Templates http://s3.amazon.com/{bucket-name}/{object-name} http://mysite.com/users/{user-name}/photos http://google.com/search?q={search-query}
Start URL + Links https://bank.com/accounts/345095 <account> <name>Tina Jones</name> <link rel="history" href="/tjones/account_history"> <link rel="close" verb="delete" href="/tjones"> </account>
Microformats <account> <name>Tina Jones</name> <link rel="transaction-search" href="account_history? from={date-from}& to={date-to}"> </account>
State Management http://google.com Searching Search google.com/search?q=rest Searched Next Page google.com/search?q=rest&start=10 More Results
XHTML <h1>Accounts</h1> <ul> <li> <a rel="account_details" href="/tjones">Tina Jones</a> </li> <li> .....
JSON { "account_name": "Tina Jones", "links": {"history": "/tjones/history"} }