mike carey –restdone right -...

61
Mike Carey – ReST Done Right November 2017

Upload: trinhlien

Post on 18-Mar-2018

223 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Mike Carey – ReST Done RightNovember 2017

Page 2: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Meet Mike

2008:JavaEngineeratWalmart

2010:IntroducedtoAgile(Scrum)

2011:AgileUserGroup/ScrumMaster

2013:AgileCoach

2015:DeliveryManagerinD.C.Office

2017:WalmartLabs

Page 3: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Assumptions & BaselineReST TheoryReST in the WildSo What?

Talking Points

01020304

Page 4: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Assumptions & BaselineReST TheoryReST in the WildSo What?

Talking Points

01020304

Page 5: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Who are you?

•Technical

•Non-Technical

Page 6: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

What do you want?

What are you hoping to take away from this session?

Page 7: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Assumptions & BaselineReST TheoryReST in the WildSo What?

Talking Points

01020304

Page 8: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

All the Buzzwords!

Credit:http://hyperboleandahalf.blogspot.com/2010/06/this-is-why-ill-never-be-adult.html

Page 9: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

All the Buzzwords!

• Service-Oriented Architecture (SOA)

•Microservices

• Representational State Transfer (ReST)

Page 10: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Where did ReST come from?

Page 11: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Where did ReST come from?

• Dr. Roy Fielding’s 2000 Dissertation, “Architectural Styles andthe Design of Network-based Software Architectures”

• Written as a result of defending the design choices of the Internet for 4 years in the late ‘90s

Page 12: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Why is ReST important?

• Defines a “core set of principles, properties, and constraints”

• Leverages existing HTTP standards

• Provides greater flexibility than SOAP, other protocols

Page 13: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Let’s ReST!

RepresentationalStateTransfer

Page 14: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Let’s ReST!

RepresentationalStateTransfer

Page 15: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Let’s ReST!

RepresentationalStateTransfer

Page 16: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Let’s ReST!

RepresentationalStateTransfer

Page 17: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #1

Client-Server Architecture

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Page 18: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #1

Client-Server Architecture

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Page 19: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #1

Client-Server Architecture

Allows for independent scaling of each

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Page 20: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #2

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Statelessness

Page 21: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #2

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Statelessness

Page 22: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #2

Allows for visibility, reliability, and scalabilityCredit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Statelessness

Page 23: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #3

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Cacheability

Page 24: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #3

Cacheability

Request

Response

Copy ofResponse

Page 25: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #3

Cacheability

Request

Response

Page 26: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #3

Improves efficiency, scalability, perceived performance at cost of reliability

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Cacheability

Page 27: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #4

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Uniform Interface

Page 28: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #4

Uniform Interface

vs

Page 29: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #4

Enhances simplicity & visibility at the cost of efficiency

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Uniform Interface

Page 30: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #5

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Layered System

Page 31: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #5

Simplifies components at risk of increased latency for the whole

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Layered System

Page 32: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #6

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Code on Demand (optional)

Page 33: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #6

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Code on Demand (optional)

Page 34: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Constraint #6

Potentially enhances client experience at the expense of visibility

Credit: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Code on Demand (optional)

Page 35: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Assumptions & BaselineReST TheoryReST in the WildSo What?

Talking Points

01020304

Page 36: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Where the Wild Things Are

Credit: Maurice Sendak, “Where the Wild Things Are”

Page 37: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model

• Defined by Leonard Richardson in 2008 (?)

• Best explained by Martin Fowler in 2010

• Presented to you with real life(ish) examples

Page 38: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols
Page 39: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols
Page 40: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 0

• Uses HTTP as transport system

•Does not leverage HTTP mechanisms, i.e.•Methods/Verbs• Response Codes

• SOAP, XML-RPC

Page 41: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 0

Request (POST):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

<SOAP-ENV:Header/><SOAP-ENV:Body>

<ns4:getItemDetails xmlns:ns3="http://xmlns.walmartstores.com/ns3Path" xmlns:ns4="http://xmlns.walmartstores.com/ns4Path" xmlns:ns5="http://xmlns.walmartstores.com/ns5Path">

<upcNumber>4391797660</upcNumber></ns4:getItemDetails>

</SOAP-ENV:Body></SOAP-ENV:Envelope>

Response (200 OK):

<soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-

open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"/>

</soapenv:Header><soapenv:Body>

<n:getItemDetailsResponsexmlns:n="http://www.xmlns.walmartstores.com/nPath">

<return><errors>Error Code:1000

</errors></return></n:getItemDetailsResponse>

</soapenv:Body></soapenv:Envelope>

URI: http://www.hostname.com/path/GetItemInfo

Page 42: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 0

Request (POST):

{"arg0": {

"authMethod":"","countryCd":"US","itemInfo":[{

"upc":"000004391797660"}],"languageCd":"ENG","reqDateTime":"2017-10-24","storeNbr":100

}}

Response (200 OK):

{"messageFault": {

"errorCode":200,"errorNode":null,"errorDesc":null,"errorText":"Success"

},"item": {

"details": {...

},..."xparams":null

}}

URI: http://www.hostname.com/path/GetItemInfo

Page 43: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 1

• Level 0 + Resources

• URIs are unique to resources

• Responses are Resource Representations

Page 44: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 1

Request (POST):

{"arg0": {

"authMethod":"","countryCd":"US","itemInfo":[{

"upc":"000004391797660"}],"languageCd":"ENG","reqDateTime":"2017-10-24","storeNbr":100

}}

Response (200 OK):

{"payload": {

"item": {"itemName": "FRONTLINE LARGE DOG","upc": "0000350604287200","multiPackStatus": false,"hazMat": false,"hazwaste": false,...

},"supplier": {...}

}}

URI: http://www.hostname.com/path/items/123456

Page 45: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 1

• I have not encountered in the wild

• If they think to use resources,they usually think to use HTTP verbs

Credit:http://pbfcomics.com/comics/the-last-unicorns/

Page 46: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

• Proper use of HTTP verbs

•GET• POST• PUT• PATCH•DELETE

• Read• Create• Update (wholesale)• Update (partial)•Delete

Page 47: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

•Generally also proper use of return codes

• 200 OK• 400 BAD REQUEST• 404 NOT FOUND• 418 I’M A TEAPOT• 500 INTERNAL SERVER ERROR

Page 48: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

• 62 Standard codes•Organized by category• 1xx: Informational• 2xx: Success• 3xx: Redirection• 4xx: Client Error• 5xx: Server Error

Page 49: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

Request (GET):

No Request Body

Resource-based URI

Appropriate Headers

Response (404 NOT FOUND):

{"status": "NOT_FOUND”,"header": {

"headerAttributes": {}},"errors": [

{"code": "404.LOOKUP_SERVICE.1001","field": "”,"description": "Item details not found.","info": "","severity": "ERROR","category": "REQUEST","causes": [],"errorIdentifiers": {}

}],"payload": null

}

URI: http://www.hostname.com/path/items/123456

Page 50: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

Response (200 OK):

{"payload": {

"item": {"itemName": "FRONTLINE LARGE DOG","upc": "0000350604287200","multiPackStatus": false,

"hazMat": false,"hazwaste": false,...

},"supplier": {...}

}}

URI: http://www.hostname.com/path/items/123456

Request (GET):

No Request Body

Resource-based URI

Appropriate Headers

Page 51: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 2

• At level two, you are satisfying up to 5½ of the 6 constraints

• For internal-use ReST, often hit point of diminishing returns past level 2

Page 52: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 3

•HATEOAS: Hypertext As The Engine Of Application State

• The responses document the API itself

•Makes it easier to change the API without impacting clients

Page 53: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 3

GET Response:

{"payload": [

{"upc": "0000350604287200",...,"details": "/items/123456"

},{

"upc": "0000681131159430",...,"details": "/items/789012"

},...

]}

GET Response:

{"payload": {

"item": {"itemName": "FRONTLINE LARGE DOG","upc": "0000350604287200","multiPackStatus": false,

"hazMat": false,"hazwaste": false,...

},"supplier": "/suppliers/123456"

}}

URI: http://www.hostname.com/path/items URI: http://www.hostname.com/path/items/123456

Page 54: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Richardson Maturity Model – Level 3

Credit:LisaFrank

Page 55: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Assumptions & BaselineReST TheoryReST in the WildSo What?

Talking Points

01020304

Page 56: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

Ask yourself

•Why am I building this API?

•Where are the capability boundaries?

•Who might my consumers be?

Page 57: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

What happens when…

• You aren’t right-sized and cohesive?

• Are you violating the:• Client-Server Architecture constraint?• Layered System constraint?

Page 58: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

What happens when…

• You aren’t resource-driven?

• Are your URIs resources?• Are your responses stateless

representations?

Page 59: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

What happens when…

• You don’t leverage HTTP standards?

•How easy is your API to• Consume?• Cache?• Change?

Page 60: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols

“”To succeed in this world, you have to change all the time.

Sam Walton, Walmart Founder

Page 61: Mike Carey –ReSTDone Right - agiledaytwincities.orgagiledaytwincities.org/wp-content/uploads/2017/11/Mike-Carey-ReST.pdf · •Provides greater flexibility than SOAP, other protocols