tre ubeleilige sannheter om rest

27
TRE UBELEILIGE SANNHETER OM REST COMPUTASDAG, 13. JUNI 2014 1

Upload: filip-van-laenen

Post on 05-Dec-2014

226 views

Category:

Software


4 download

DESCRIPTION

Three Inconvenient Thruths about REST

TRANSCRIPT

TRE UBELEILIGE SANNHETER OM REST

COMPUTASDAG, 13. JUNI 2014

1

2Fra: http://martinfowler.com/articles/richardsonMaturityModel.html

SANNHET #1:

GET-kall er aldri nullipotent

3

4Fra: http://martinfowler.com/articles/richardsonMaturityModel.html

Hva betyr «nullipotent»?

5

Fra Wikipedia:

«The GET method is a safe method (or nullipotent), meaning that calling it produces no side-effects.»

6

Tomcat Access Log

Moteksempler

● Access log som REST-ressurs

● Tilgangskontroll– Three strikes-regel

● Engangsnedlasting

7

SANNHET #2:

HTTP Response Codes ≠ «REST Response Codes»

8

9Fra: http://martinfowler.com/articles/richardsonMaturityModel.html

10Fra: http://www.restapitutorial.com/httpstatuscodes.html

11Fra: http://www.restapitutorial.com/httpstatuscodes.html

12Fra: http://www.restapitutorial.com/httpstatuscodes.html

13Fra: http://www.restapitutorial.com/httpstatuscodes.html

Martin Fowler om HATEOAS

14

«The key elements that are supported by the existence of the web are the strong separation between safe (eg GET) and non-safe operations, together with using status codes to help communicate the kinds of errors you run into.»

http://martinfowler.com/articles/richardsonMaturityModel.html

SANNHET #3:

HATEOAS YAGNI⇒

15

16Fra: http://martinfowler.com/articles/richardsonMaturityModel.html

HATEOAS

17

Hypermedia as the engine of application state

Fra Wikipedia:

«Clients make state transitions only through actions that are dynamically identified within hypermedia by the server.

Except for simple fixed entry points to the application, a client does not assume that any particular action is available for any particular resources beyond those described in representations previously received from the server.»

Eksempel: Hire i EPIM LogisticsHub

18

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/></Hire>

Eksempel: Hire i EPIM LogisticsHub

19

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/></Hire>

Eksempel: Hire i EPIM LogisticsHub

20

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/></Hire>

199 av totalt 477 tegn(42%)

Eksempel: Hire i EPIM LogisticsHub, full HATEOAS

21

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/> <Link href="/organizations/123456789" method="get" rel="Organization"/> <Link href="/organizations/123456789/locations/1234567890123" method="get" rel="Location"/> <Link href="/ccus/141705/hires/a1/hires/h101442/documents" method="post" rel="Documents"/> <Link href="/ccus/141705/hires/a1/hires/h101442" method="put" rel="update"/> <Link href="/ccus/141705/hires/a1/hires/h101442/hires" method="post" rel="addHire"/></Hire>

620 av totalt 899 tegn(69%)

Martin Fowler om HATEOAS

22

«One obvious benefit of hypermedia controls is that it allows the server to change its URI scheme without breaking clients. As long as clients look up the “addTest” link URI then the server team can juggle all URIs other than the initial entry points.»

http://martinfowler.com/articles/richardsonMaturityModel.html

Martin Fowler om HATEOAS

23

«A further benefit is that it helps client developers explore the protocol. The links give client developers a hint as to what may be possible next. It doesn't give all the information: both the “latest” and “cancel” controls point to the same URI – they need to figure out that one is a GET and the other a DELETE. But at least it gives them a starting point as to what to think about for more information and to look for a similar URI in the protocol documentation.»

http://martinfowler.com/articles/richardsonMaturityModel.html

Kost/nytte av HATEOAS

Hva endrer seg oftest?● Oppførsel● Innhold● URLer

Hva er vanskelig å refaktorere?● Oppførsel● Innhold● URLer

24

Eksempel: Hire i EPIM LogisticsHub

25

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">b2</EnclosingHireId> <EnclosingHireId distance="2">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/> <Link href="/organizations/123456789" method="get" rel="Organization"/> <Link href="/organizations/123456789/locations/1234567890123" method="get" rel="Location"/> <Link href="/ccus/141705/hires/a1/hires/h101442/documents" method="post" rel="Documents"/> <Link href="/ccus/141705/hires/a1/hires/h101442" method="put" rel="update"/> <Link href="/ccus/141705/hires/a1/hires/h101442/hires" method="post" rel="addHire"/></Hire>

Eksempel: Hire i EPIM LogisticsHub

26

<Hire id="h101442"> <CcuId>141705</CcuId> <EnclosingHireIds> <EnclosingHireId distance="1">b2</EnclosingHireId> <EnclosingHireId distance="2">a1</EnclosingHireId> </EnclosingHireIds> <OrgNo>123456789</OrgNo> <GlnLocation>1234567890123</GlnLocation> <StartDate>2013-10-09</StartDate> <EndDate>2013-11-08</EndDate> <Link href="/ccus/141705/hires/a1/hires/h101442" method="get" rel="self"/> <Link href="/ccus/141705" method="get" rel="Ccu"/> <Link href="/ccus/141705/hires/a1" method="get" rel="EnclosingHire"/> <Link href="/organizations/123456789" method="get" rel="Organization"/> <Link href="/organizations/123456789/locations/1234567890123" method="get" rel="Location"/> <Link href="/ccus/141705/hires/a1/hires/h101442/documents" method="post" rel="Documents"/> <Link href="/ccus/141705/hires/a1/hires/h101442" method="put" rel="update"/> <Link href="/ccus/141705/hires/a1/hires/h101442/hires" method="post" rel="addHire"/></Hire>

HATEOAS

27

● Bruker mye båndbredde● For å kunne slippe å refaktorere

noe som er lett å refaktorere● Og som nesten aldri endrer seg

● YAGNI (You aren't gonna need it)