The API Facade Pattern: Common Patterns - Episode 2
-
Upload
apigee -
Category
Technology
-
view
9.347 -
download
0
Transcript of The API Facade Pattern: Common Patterns - Episode 2
API Façade: Common Patterns
Episode 2Webinar ShortsMarch 2012 Series
Brian Mulloy@landlessness
Apigee@apigee
Episode 1The API Facade: OverviewTuesday, March 6th
Episode 2The API Facade: Common PatternsTuesday, March 13th
Episode 3The API Facade: TechnologyTuesday, March 20th
Episode 4The API Facade: PeopleTuesday, March 27th
Webinar Shorts - March 2012 New!
Episode 2 Topics
• Recap: API façade• Errors• Stubs• URLs• Versioning• Data formats• Internal & external systems
RSSObjects
XML
App
1. Build up from systems of record
1.
Big System
DBContent
Management SOAP JDBC RSS
Tables
XML
RSS
XMLXML
Tables
XML
RSS
XML
One Big Problem
1. Design the Ideal API2. Implement Design with Stubs as Façade3. Mediate between Façade and SystemsApp
Developer
Mediate
API Facade
1.
2.
3.
Big System
DBContent
Management SOAP JDBC RSS
Ideal Design
Three Small Problems
API Facade
Errors
Request Response
nothing to see here
200 201 304 400 401 403 404 500
{“developerMessage”:“Verbose, plain language description of the problem for the app developer with hints about how to fix it.”,“userMessage”:“Pass this message on to the app user, if needed.”,"errorCode":12345, ”status":401,“moreInfo”:“http://dev.teachdogrest.com/errors/12345”}
API Facade
Errors
Request Response
nothing to see here
GET /products?raise=500
(don’t support raise in production)
API Facade
Stubs
Request Response
nothing to see here
{"products”: [ {"product":{"id":"1234”,"name":"Widget”, "color":"white"}},{"product":{"id":"1235”, "name":"Gadget”, "color":"brown"}} ]}
API Facade
Stubs
Request Response
nothing to see here
GET /products?mock=true
(don’t support mock in production)
API Facade
Support Limited Clients
Request Response
Big System
DELETE /services/data/v20.0/sobjects/Account/123
GET /v2/accounts/123?method=delete
API Facade
Versioning
Request
GET /v2/accounts GET /v3/accounts
Big OldSystem
New UntriedSystem
GET old.internal.com/accounts GET new.internal.com/accounts
SOAP
API Facade
Request Response
/services/data/v20.0/sobjects/Account
POST /v2/accounts.xml
SOAP
Data FormatsSOAP
SOAP
API Facade
Request Response
/services/data/v20.0/sobjects/Account
GET /v2/accounts.json
SOAP
Data FormatsJSON
Should the version number appear in the URL immediately after the domain name or is it better to have application name after domain name? Billing accounts /accounts/v2/create?
Q&A
How can a GET request be transformed to a SOAP POST, specifically when the SOAP POST request size is huge?
Q&A
What about version in the request header instead of putting it in the URL, what would the drawback be of using it in the request header?
Q&A
Should every response follow a standard format that contains errors, if any, along with response body or should the response body change based on success or failure of the operation?
Q&A
For the API I am hosting façade pattern makes sense, but for the external systems where I am consuming APIs, factory seems more appropriate. What’s your take?
Q&A
Get flash accounts should return all accounts right? Wouldn’t want to prevent this, what would a URL request look like? If you’re reflecting a response from the database where the state=Washington, how would that work?
Q&A