REST - Machadogj.com

bubblemessengerΑσφάλεια

5 Νοε 2013 (πριν από 4 χρόνια και 5 μέρες)

102 εμφανίσεις

1

2

RESTful

Services

‘a la
carte


Gustavo Javier Machado

Architect

Tellago

Inc
.

gustavo.machado@tellago.com

http://thegsharp.wordpress.com

3

Agenda


REST


REST & Microsoft


WCF
WebHttp


WCF
DataServices


MVC 2


When to use what?

REST

5

REST



Representational

State

Transfer
.
Architecture style




Better use of HTTP


Less complexity


Better interoperability



6

REST

-

Principles



Examples
:





REST


Principle 1

:
Returns a representation of the resource

:
Updates the resource

:
Creates a resource

:
Deletes a resource

REST


Principle 2


<
order self=’http://example.com/orders/1234’>

<amount>23</amount>

<product ref=’http://example.com/products/4554’ />

<customer ref=’http://example.com/customers/1234’ />

</order>


REST


Principle 3


GET
/accounts('UBS')

Host: restsamples.com

Accept: application/
atom+xml




GET /accounts('UBS')

Host: restsamples.com

Accept: application/
json




REST


Principio 4



GET
/accounts('
ubs
')

Host: restsamples.com

Accept: application/
account+xml


<account><contact ref="/contacts('ubs
-
12345')">...</contact></account>



GET /contacts('ubs
-
12345')

Host: restsamples.com

Accept: application/
contact+xml


<contact id="ubs
-
12345">...</contact>

REST


Principio 5

RESTfulness



RESTafaris





Microsoft & REST

Microsoft & REST

Public class Service:
IContract

{


[
WebGet
]


Type Operation1(parameters….);


.


.


.


[
WebInvoke
]


Type
Operationn
(parameters….);

}

XML

JSON

Atom

Microsoft y REST

Public class
MyContext

:
IUpdatable

{


IQueryable
<T1> field1;


.


.


.


IQueryable
<
Tn
>
fieldn
;

}

AtomP

JSON

ODATA

Microsoft y REST

Public class Service : Controller

{


ActionResult

Action1(parameters…);


.


.


.


ActionResult

Actionn
(parameters…);

XML

JSON

Atom

Microsoft y REST

WCF WebHttp

19


WCF Webhttp

20


.NET 4.0

.NET 3.5

WCF Webhttp

http://myservice/Greetings/
Gustavo

<string
xmlns
="http://schemas.microsoft.com/2003/10/Ser
ialization/">Hello
Gustavo
</string>

22

Uri template

Http Verb

Help page

Format

Links

Error codes


23

Questions


24

WCF DataServices

25

WCF Dataservices

26

WCF Dataservices

27

WCF Dataservices

Public class
MyContext

:
IUpdatable

{


IQueryable
<T1> field1;


.


.


.


IQueryable
<
Tn
>
fieldn
;

}

ODATA

AtomP

JSON

28

Public class
MyContext

:
IUpdatable

{


.

}

WCF Dataservices

29

Custom Container

EF client/
servidor

AccessRules

Service Operations

30

ASP .NET MVC

31

ASP

.NET MVC

Public class Service : Controller

{


ActionResult

Action1(parameters…);


.


.


.


ActionResult

Actionn
(parameters…);

XML

JSON

Atom

32

ASP

.NET MVC

Web

Uris

Format

33

When to use what?

34

When

to

use WCF
WebHttp

Full control

to design operations

to expose a SOAP version

If you want…

35

When

to

use WCF
Dataservice

to expose a Data Model

to provide querying capability

to abstract DAL from your
application

If you want…

36

When

to

use ASP .NET

MVC

to consume from the client side
of a website

to provide an HTML version of
the resource

If you want…

37

Gustavo Machado

Gustavo.machado@tellago.com

http://thegsharp.wordpress.com

http://twitter.com/machadogj

http://ar.linkedin.com/in/machadogj


Contact

information


38

© 2008 Microsoft Corporation.
Todos

los
derechos

reservados
. Microsoft, Windows, Windows Vista y
otros

nombres

de
producto

son y
pueden

ser
marcas

registradas

y
registros

en
Estados

Unidos

y en
otros

países
.

La
información

contenida

en el
presente

es

sólo

para

fines
informativos

y
representa

la
visión

actual de
Microsoft Corporation a la
fecha

de
esta

presentación
.
Debido

a
que

Microsoft
debe

responder a
las

cambiantes

condiciones

del
mercado
, no se
debe

interpretar

como

un
compromiso

por

parte de Microsoft, y
Microsoft no
puede

garantizar

la
precisión

de
ninguna

información

provista

después

de la
fecha

de
esta

presentación
. MICROSOFT NO OFRECE GARANTÍA ALGUNA, EXPRESA, IMPLÍCITA O DE LEY, RESPECTO A LA
INFORMACIÓN EN ESTA PRESENTACIÓN.