why do you need rest

18
© 2012 MPS Partners.. All rights reserved. Why do you need REST June 27, 2013 Brown Bag presentation by: Mayank Srivastava www.MayankSrivastava.com

Upload: mayank-srivastava

Post on 05-Dec-2014

1.182 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Why do you need REST

© 2012 MPS Partners.. All rights

reserved.

Why do you need REST

June 27, 2013

Brown Bag presentation by: Mayank Srivastavawww.MayankSrivastava.com

Page 2: Why do you need REST

Agenda

o Understanding REST

o REST Vs. SOAP

o Web API Vs. WCF

o Web API features.

Page 3: Why do you need REST

3

Interaction over HTTP

Page 4: Why do you need REST

4

Interaction over HTTP

Page 5: Why do you need REST

5

What is SOAP?

• An XML info set based on messaging protocol.

• SOAP messages have an envelope, headers and a body

• Transport neutral “interoperable” model.

• RPC based development approach.

Page 6: Why do you need REST

6

What is REST

• REST = Representational State Transfer –

As introduced by Roy Fielding in 2000

• REST is the architectural style for the Web, to building services hosted and

consumed over HTTP.

Uniform interface, HTTP Data formats & Content types, client-server, stateless, cacheable, scalable.

General Use of terms:

RESTful Service

HTTP Service

No SOAP

WEB API == HTTP Service == RESTful Service.

Page 7: Why do you need REST

7

REST Vs. SOAP

• SOAP focuses on verbs (methods) while REST focuses on noun (resource)

SOAP:

.GetProduct()

.UpdateLocations()

.DeleteUser()

REST: (Uniform Interface HTTP verbs)

Product { }

Location { }

User { }

With SOAP you define custom operation that tunnel thru POST

SOAP is a message protocol where REST is an architectural design for the web

Page 8: Why do you need REST

8

Why REST?

• Do you need transport neutrality?

• Do you need WS* features?

• Benefits of already developed Web features like caching and scalability.

• Basic SOAP is just like REST but without the benefits.

• Fewer code transition layers

• It is the standard for communication in the “cloud”.

• Universal interface that everyone understands.

Page 9: Why do you need REST

9

Why REST?

What about security?

All the your Web application supports

• Token based

• Active directory

• OAuth 2.0

Client Server

Resource request

Redirect to credential challenge

Credentials

Links and tokens to access resource & access token

Page 10: Why do you need REST

10

Universal interface that everyone understands.

Your RESTful Service

Page 11: Why do you need REST

11

Example SOAP message over HTTP

POST http://wcftest.azurewebsites.net/Service1.svc HTTP/1.1

Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IStockTicker/GetQuote"

Host: wcftest.azurewebsites.net

Content-Length: 168

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">

<s:Body>

<GetQuote xmlns="http://tempuri.org/">

<stockTicker>MSFT</stockTicker>

</GetQuote>

</s:Body>

</s:Envelope>

</s:Envelope>

______________________________________________________________________________________________________________________

HTTP/1.0 200 OK

Content-Length: 187

Content-Type: application/soap+xml; charset=utf-8

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">

<s:Body>

<GetQuoteResponse xmlns="http://tempuri.org/">

<GetQuoteResult>28.33</GetQuoteResult>

</GetQuoteResponse>

</s:Body>

</s:Envelope>

Page 12: Why do you need REST

12

Example “RESTful” request/response

GET http://webapitest.azurewebsites.net/stocks?symbol=msft HTTP/1.1

Host: webapitest.azurewebsites.net

______________________________________________________________________________________________________________________

HTTP/1.0 200 OK

Content-Length: 5

Content-Type: application/json; charset=utf-8

33.12

Page 13: Why do you need REST

13

Why SOAP

• SOAP interoperability is a requirement

• Non HTTP transports - TCP, UDP, Named Pipes, MSMQ, custom bindings

• WS-* based security.

Page 14: Why do you need REST

14

Implementation Options

WCF

• WCF classic

• WCF Data Services

• WCF RIA Services

• WCF Web HTTP (aka WCF REST)

ASP.NET

• ASP.NET Web Services

• ASP.NET MVC

• ASP.NET Web API

• ASP.NET Web API OData

• ASP.NET SignalR

Page 15: Why do you need REST

15

Recommendation:

WCF

• WCF classic

• WCF Data Services

• WCF RIA Services

• WCF Web HTTP (aka WCF REST)

ASP.NET

• ASP.NET Web Services

• ASP.NET MVC

• ASP.NET Web API

• ASP.NET Web API OData

• ASP.NET SignalR

For SOAP ------ WCF classic

For REST ------ ASP.NET WEB API

Page 16: Why do you need REST

16

ASP.NET Web API (Code Demos)

• Simplicity

• Self Hosting

• Consuming from Server Side.

• Attribute routing - http://attributerouting.net/

• OData (emerging functionalities)

Page 17: Why do you need REST

17

ASP.NET SignalR (Code Demos)

• Web socket based communication.

• Falls back to poll approach in the browser doesn’t support Web socket.

• http://signalr.net/

Page 18: Why do you need REST

18

Questions?