Title: James Crisp
1(No Transcript)
2(No Transcript)
3James Crisp
4(No Transcript)
5The Web
6-ilities
7Scalability
8Recoverability Reliability
9Security
10Discoverability
11(No Transcript)
12How to bring to Web services?
13Tunneling
RPC URLs POX SOAP WS-
14REpresentational State Transfer
15(No Transcript)
16REST contributes ... the rationale behind the
modern Web's software architecture... --
Roy Fielding
17Resources e.g. Person, Car, Post
18Representations
ltpersongt ltnamegtBill Gateslt/namegt
ltgendergtmlt/gendergt lt/persongt
19(No Transcript)
20Addressability
http//mysite.com/people/joe_citizen http//mysit
e.com/people/joe_citizen/friends
21Uniform Interface
22GET POST HEAD PUT DELETE OPTIONS
Support
23GET
GET /people/joe_citizen HTTP/1.1 Host
mysite.com Accept application/xml
24Response
200 OK Content-Type application/xml Last-Modified
2008-1-1 1500.. ltpersongt ltnamegtJoe
Citizenlt/namegt ltagegt42lt/agegt
ltgendergtmlt/gendergt lt/persongt
25HEAD
HEAD /people/joe_citizen HTTP/1.1 Host
mysite.com
200 OK Content-Type application/xml Last-Modified
2008-1-1 1500.. ETag a32daf15-b33da2a4d
Response
26POST
POST /people HTTP/1.1 Content-Type
text/xml Host mysite.com .... ltpersongt
ltnamegtTina Joneslt/namegt ltagegt25lt/agegt
ltgendergtFlt/gendergt lt/persongt
27Response
201 CREATED Location /people/tina_jones (optiona
lly with body)
28PUT
PUT /people/tina_jones HTTP/1.1 Content-Type
text/xml Host mysite.com .... ltpersongt
ltnamegtTina Joneslt/namegt ltagegt24lt/agegt
ltgendergtFlt/gendergt lt/persongt
29Response
200 OK Location /people/tina_jones (optionally
with body)
30DELETE
DELETE /people/joe_citizen HTTP/1.1 Host
mysite.com
200 OK Content-Type application/xml ltadminperson
Deletedgt joe_citizen lt/adminpersonDeletedgt
Response
31OPTIONS
OPTIONS /people HTTP/1.1 Host mysite.com
Response
200 OK Allowed GET,HEAD,POST
32Status Codes
332xx All good 200 OK 201 Created
343xx Redirect 301 Moved permanently 307
Temporary redirect304 Not modified (ie, see
cache)
354xx Client error 400 Bad request 401
Unauthorized 403 Forbidden 405 Method not
allowed 409 Conflict
365xx Server error 500 Internal server error
37Headers
38Content-Type text/html application/xml image/jpe
g ....
39WWW-Authenticate Authorization
40Last-Modified If-Modified-Since ETag If-None-M
atch
41Location
42Describe your services?
43URI Templates http//s3.amazon.com/bucket-name/
object-name http//mysite.com/users/user-name
/photos http//google.com/search?qsearch-query
44Start URL Links
https//bank.com/accounts/345095 ltaccountgt
ltnamegtTina Joneslt/namegt ltlink rel"history"
href"/tjones/account_history"gt ltlink
rel"close" verb"delete"
href"/tjones"gt lt/accountgt
45Microformats
ltaccountgt ltnamegtTina Joneslt/namegt ltlink
rel"transaction-search" href"account_histo
ry? fromdate-from todate-to"gt lt/accou
ntgt
46State Management
http//google.com
Searching
Search
google.com/search?qrest
Searched
Next Page
google.com/search?qreststart10
More Results
47Data Format?
48XHTML
lth1gtAccountslt/h1gt ltulgt ltligt lta
rel"account_details" href"/tjones"gtTina
Joneslt/agt lt/ligt ltligt .....
49JSON
"account_name" "Tina Jones",
"links" "history" "/tjones/history"
50ltXMLgtlt/XMLgt
51Framework
52Ordering Pizza
53http//epizza.com
GET / HTTP/1.1 Host epizza.com Content-Type
application/xml
54Response
200 OK Location http//epizza.com Content-Type
application/xml Content-Length ... ltepizza
xmlns"/schema"gt ltmessagegtWelcome!lt/messagegt
ltlink rel"menu" href"/menu" /gt ltlink
rel"place-order" href"/orders"
/gt ltepizzagt
55Let's see the menu!
GET /menu HTTP/1.1 Host epizza.com Content-Type
application/xml
56Menu Response
200 OK Location ... ltepizza xmlns"/schema"gt
ltmenugt ltpizza name"pepperoni"gt
ltingredientsgt...lt/ingredientsgt lt/pizzagt
... ltmenugt ltlink rel"place-order"
href"/orders" /gt lt/epizzagt
57Ordering time!
POST /orders HTTP/1.1 Host epizza.com Content-Typ
e application/xml Content-Length ... ltorder
xmlns"/schema"gt ltpizza name"pepperoni"
/gt lt/ordergt
58Place Order Response
201 Created Location http//epizza.com/orders/413
Content-Type ... ltepizza xmlns"/schema"gt
ltordergt ltpizza name"pepperoni" /gt
lt/ordergt ltlink rel"destination"
href"/orders/413/address"gt lt/epizzagt
59Beer with that?
60OPTIONS /orders/413 HTTP/1.1 Host epizza.com
200 OK Allowed GET, HEAD, POST, PUT
61Add Beer
POST /orders/413 HTTP/1.1 Host
epizza.com Content-Type application/xml Content-L
ength ... ltorder xmlns"/schema"gt ltdrink
name"corona" /gt lt/ordergt
62Response
200 OK Location http//epizza.com/orders/413 Cont
ent-Type ... ltepizza xmlns"/schema"gt
ltordergt ltpizza name"pepperoni" /gt ltdrink
name"corona" /gt lt/ordergt ltlink
rel"destination" href"/orders/413/destinatio
n"gt lt/epizzagt
63Destination Address
PUT /orders/413/address HTTP/1.1 Host
epizza.com Content-Type application/xml Content-L
ength ... ltaddress xmlns"/schema"gt ltline1gt35
Rue Rdlt/line1gt ltsuburbgtPotts Pointlt/suburbgt lt/ad
dressgt
64Destination Response
200 OK Host epizza.com Content-Type
application/xml Content-Length ... ltaddress
xmlns"/schema"gt ltline1gt35 Rue Rdlt/line1gt
ltsuburbgtPotts Pointlt/suburbgt lt/addressgt
65GET /orders/413
200 OK Location http//epizza.com/orders/413 Cont
ent-Type ... ltepizza xmlns"/schema"gt
ltordergt ltpizza name"pepperoni" /gt ltdrink
name"corona" /gt lt/ordergt lt/epizzagt
66(No Transcript)
67Can we?
OPTIONS /orders/413 HTTP/1.1 Host epizza.com
200 OK Allowed GET, HEAD
68Too late!
69(No Transcript)
70Back at the ePizza Kitchen..
71GET /orders
72Implementation
73Client
var request (HttpWebRequest)
WebRequest.Create(URL) request.Method request.Co
ntentType request.GetRequestStream() var
response (HttpWebResponse)request.GetResponse()
response.StatusCode response.Headers response.G
etResponseStream()
74(No Transcript)
75Server
76IHttpHandler
public class RestHandler IHttpHandler
public void ProcessRequest(HttpContext context)
context.Response.ContentType
"application/xml" if (context.Request.HttpM
ethod "GET") context.Response.Write
("ltxmlgt...lt/xmlgt")
77WCF REST
ServiceContract public interface
IPizzaService WebGet(UriTemplate"/orders/ord
erId") OperationContract Order GetOrder(int
orderId)
78Status codes? Headers? Links? Microformats?
79ASP.NET MVC
80Routing Table
Controller Method
Model
View
81Routes
In GlobalApplication HttpApplication void
RegisterRoutes(RouteCollection routes)
routes.MapRoute( "AddToOrder",
"orders/id", new controller "Orders",
action "AddToOrder" ,
new httpMethod new
HttpMethodConstraint("POST")) ...
82Controller
public class OrdersController Controller
public ActionResult AddToOrder(int id)
var order Order.Load(id) var itemToAdd
CreateMenuItemFromRequest()
order.Items.Add(itemToAdd) order.Save()
// response.StatusCode 200 return
View(order)
83Model
public class Order public MenuItem Items
get ... public Address
DeliveryAddress get set
84View
lt_at_ Page Language"C" ...gt ltepizza
xmlns"/schema"gt ltordergt lt foreach (var
item in Order.Items) gt ltpizza name "lt
item.Name gt" /gt lt gt lt/ordergt lt if
(Order.DeliveryAddress null) gt ltlink
rel"destination" href ... lt/epizzagt
85MVC REST Wrinkles
86(No Transcript)
87See also... Slides Code http//www.jamescrisp.
org MVC http//www.asp.net/mvc/
RESTful Web Services
88Image References
http//flickr.com/photos/misserion/2190827125/ -
web http//flickr.com/photos/hyougushi/412600118/
- bridge http//en.wikipedia.org/wiki/ImageIntern
et_map_1024.jpg - web http//flickr.com/photos/gra
din/3361527/ - defibrillator http//flickr.com/pho
tos/keoki/1418303458/ - padlocks http//roadmap.cb
diforum.com/reports/protocols/ - ws
stack http//flickr.com/photos/chainsawpanda/15288
94/ - tunnel http//flickr.com/photos/psd/42118657
8/ - fielding http//flickr.com/photos/esparta/187
132368/ - bill gates http//flickr.com/photos/acme
_explosives/117276632/ - network
plugs http//flickr.com/photos/walterhertman/10148
9766/ - speedometers http//flickr.com/photos/sis/
5908199/ - Petco explosion http//flickr.com/photo
s/pleasewait/476776136/ - letter http//flickr.com
/photos/bigpinkcookie/108895725/ - Eiffel
tower http//flickr.com/photos/bala_/2077047513/
- pizza restaurant http//flickr.com/photos/572317
35_at_N00/201482385/ - pepperoni pizza http//flickr.
com/photos/sheeshoo/10321250/ -
corona http//flickr.com/photos/freddy/39340695/
- salad http//flickr.com/photos/huthfamily/130433
6305/ - 42 pizza boxes http//www.crummy.com/writi
ng/RESTful-Web-Services/cover.png REST book
89Questions?