James Crisp - PowerPoint PPT Presentation

1 / 89
About This Presentation
Title:

James Crisp

Description:

James Crisp – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 90
Provided by: james164
Category:
Tags: crisp | james | jug

less

Transcript and Presenter's Notes

Title: James Crisp


1
(No Transcript)
2
(No Transcript)
3
James Crisp
4
(No Transcript)
5
The Web
6
-ilities
7
Scalability
8
Recoverability Reliability
9
Security
10
Discoverability
11
(No Transcript)
12
How to bring to Web services?
13
Tunneling
RPC URLs POX SOAP WS-
14
REpresentational State Transfer
15
(No Transcript)
16
REST contributes ... the rationale behind the
modern Web's software architecture... --
Roy Fielding
17
Resources e.g. Person, Car, Post
18
Representations
ltpersongt ltnamegtBill Gateslt/namegt
ltgendergtmlt/gendergt lt/persongt
19
(No Transcript)
20
Addressability
http//mysite.com/people/joe_citizen http//mysit
e.com/people/joe_citizen/friends
21
Uniform Interface
22
GET POST HEAD PUT DELETE OPTIONS
Support
23
GET
GET /people/joe_citizen HTTP/1.1 Host
mysite.com Accept application/xml
24
Response
200 OK Content-Type application/xml Last-Modified
2008-1-1 1500.. ltpersongt ltnamegtJoe
Citizenlt/namegt ltagegt42lt/agegt
ltgendergtmlt/gendergt lt/persongt
25
HEAD
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
26
POST
POST /people HTTP/1.1 Content-Type
text/xml Host mysite.com .... ltpersongt
ltnamegtTina Joneslt/namegt ltagegt25lt/agegt
ltgendergtFlt/gendergt lt/persongt
27
Response
201 CREATED Location /people/tina_jones (optiona
lly with body)
28
PUT
PUT /people/tina_jones HTTP/1.1 Content-Type
text/xml Host mysite.com .... ltpersongt
ltnamegtTina Joneslt/namegt ltagegt24lt/agegt
ltgendergtFlt/gendergt lt/persongt
29
Response
200 OK Location /people/tina_jones (optionally
with body)
30
DELETE
DELETE /people/joe_citizen HTTP/1.1 Host
mysite.com
200 OK Content-Type application/xml ltadminperson
Deletedgt joe_citizen lt/adminpersonDeletedgt
Response
31
OPTIONS
OPTIONS /people HTTP/1.1 Host mysite.com
Response
200 OK Allowed GET,HEAD,POST
32
Status Codes
33
2xx All good 200 OK 201 Created
34
3xx Redirect 301 Moved permanently 307
Temporary redirect304 Not modified (ie, see
cache)
35
4xx Client error 400 Bad request 401
Unauthorized 403 Forbidden 405 Method not
allowed 409 Conflict
36
5xx Server error 500 Internal server error
37
Headers
38
Content-Type text/html application/xml image/jpe
g ....
39
WWW-Authenticate Authorization
40
Last-Modified If-Modified-Since ETag If-None-M
atch
41
Location
42
Describe your services?
43
URI Templates http//s3.amazon.com/bucket-name/
object-name http//mysite.com/users/user-name
/photos http//google.com/search?qsearch-query
44
Start 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
45
Microformats
ltaccountgt ltnamegtTina Joneslt/namegt ltlink
rel"transaction-search" href"account_histo
ry? fromdate-from todate-to"gt lt/accou
ntgt
46
State Management
http//google.com
Searching
Search
google.com/search?qrest
Searched
Next Page
google.com/search?qreststart10
More Results
47
Data Format?
48
XHTML
lth1gtAccountslt/h1gt ltulgt ltligt lta
rel"account_details" href"/tjones"gtTina
Joneslt/agt lt/ligt ltligt .....
49
JSON
"account_name" "Tina Jones",
"links" "history" "/tjones/history"
50
ltXMLgtlt/XMLgt
51
Framework
52
Ordering Pizza
53
http//epizza.com
GET / HTTP/1.1 Host epizza.com Content-Type
application/xml
54
Response
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
55
Let's see the menu!
GET /menu HTTP/1.1 Host epizza.com Content-Type
application/xml
56
Menu 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
57
Ordering 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
58
Place 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
59
Beer with that?
60
OPTIONS /orders/413 HTTP/1.1 Host epizza.com
200 OK Allowed GET, HEAD, POST, PUT
61
Add 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
62
Response
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
63
Destination 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
64
Destination 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
65
GET /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)
67
Can we?
OPTIONS /orders/413 HTTP/1.1 Host epizza.com
200 OK Allowed GET, HEAD
68
Too late!
69
(No Transcript)
70
Back at the ePizza Kitchen..
71
GET /orders
72
Implementation
73
Client
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)
75
Server
76
IHttpHandler
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")
77
WCF REST
ServiceContract public interface
IPizzaService WebGet(UriTemplate"/orders/ord
erId") OperationContract Order GetOrder(int
orderId)
78
Status codes? Headers? Links? Microformats?
79
ASP.NET MVC
80
Routing Table
Controller Method
Model
View
81
Routes
In GlobalApplication HttpApplication void
RegisterRoutes(RouteCollection routes)
routes.MapRoute( "AddToOrder",
"orders/id", new controller "Orders",
action "AddToOrder" ,
new httpMethod new
HttpMethodConstraint("POST")) ...

82
Controller
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)
83
Model
public class Order public MenuItem Items
get ... public Address
DeliveryAddress get set
84
View
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
85
MVC REST Wrinkles
86
(No Transcript)
87
See also... Slides Code http//www.jamescrisp.
org MVC http//www.asp.net/mvc/
RESTful Web Services
88
Image 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
89
Questions?
Write a Comment
User Comments (0)
About PowerShow.com