23
All Aboard the Boxcar! Going Beyond the Basics of REST Pat Patterson Developer Evangelist Architect [email protected] @metadaddy

All Aboard the Boxcar! Going Beyond the Basics of REST

Embed Size (px)

Citation preview

Page 1: All Aboard the Boxcar! Going Beyond the Basics of REST

All Aboard the Boxcar!Going Beyond the Basics of REST

Pat PattersonDeveloper Evangelist [email protected]@metadaddy

Page 2: All Aboard the Boxcar! Going Beyond the Basics of REST

Safe harbor statement under the Private Securities Litigation Reform Act of 1995:This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

Safe Harbor

Page 3: All Aboard the Boxcar! Going Beyond the Basics of REST

RESTful principles

When our REST API ran out of steam

The Boxcar

Composite resources – still REST?

Agenda

Page 4: All Aboard the Boxcar! Going Beyond the Basics of REST

RESTful PrinciplesFielding’s Masterpiece

Page 5: All Aboard the Boxcar! Going Beyond the Basics of REST

Client-Server• Separate UI from Data Storage• Independent evolution of componentsStateless• Each request is self-contained• Visibility, reliability, scalabilityCache• Responses labeled as cacheable, or not• Efficiency, scalability, performance

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

Fielding’s Six Constraints

Page 6: All Aboard the Boxcar! Going Beyond the Basics of REST

Uniform Interface• Decouple implementations from services• Trade-off: degraded efficiencyLayered System• Each component cannot see beyond

the next layer

Code-On-Demand (optional)• Extend client functionality via applets (!)

or scripts

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

Fielding’s Six Constraints

Page 7: All Aboard the Boxcar! Going Beyond the Basics of REST

Identification of resources• Resource: “any information that can be named”Manipulation of resources through representations• Current or intended state of resourceSelf-descriptive messages• Metadata: e.g. media type, last modified timeHypermedia as the engine of application state• Resource navigation via links contained in the representation

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

Uniform Interface

Page 8: All Aboard the Boxcar! Going Beyond the Basics of REST

Resources identified by URIs• http://api.example.com/widgets/w000123

Representation by Internet media types• JSONHTTP with standard methods• GET, PUT, POST, DELETE, PATCHHypertext links between resources• No ‘magic knowledge’ driving interaction

REST in Practice - 2015

Page 9: All Aboard the Boxcar! Going Beyond the Basics of REST

Force.com REST API DemoPrinciples in Practice

Page 10: All Aboard the Boxcar! Going Beyond the Basics of REST

Transactional semantics when creating hierarchies of objects?• ‘Stateless’ REST constraint means that transaction context is

tricky

Performance with high latency networks (mobile clients)• Client framework has a message queue, wants to submit

multiple operations in a single network request

But… All Was Not Perfect in the REST API!

Page 11: All Aboard the Boxcar! Going Beyond the Basics of REST
Page 12: All Aboard the Boxcar! Going Beyond the Basics of REST

POST to /vXX.X/composite/tree/ObjectName{ "records" :[{ "attributes" : {"type" : "Account", "referenceId" : "ref1"}, "name" : "SampleAccount", "Contacts" : { "records" : [{ "attributes" : {"type" : "Contact", "referenceId" : "ref2"}, "lastname" : "Smith", "email" : [email protected] }, { "attributes" : {"type" : "Contact", "referenceId" : "ref3"}, "lastname" : "Jones", "email" : [email protected] }] } }]}

Create whole hierarchies of related objects in a single requestSolution 1: Object Trees

Page 13: All Aboard the Boxcar! Going Beyond the Basics of REST

{ "hasErrors" : false, "results" : [{ "referenceId" : "ref1", "id" : "001D000000K0fXOIAZ" },{ "referenceId" : "ref2", "id" : "001D000000K0fXPIAZ" },{ "referenceId" : "ref3", "id" : "003D000000QV9n2IAD" }] }

Object Tree Response

Page 14: All Aboard the Boxcar! Going Beyond the Basics of REST

Object Tree DemoPrinciples in Practice

Page 15: All Aboard the Boxcar! Going Beyond the Basics of REST

✔ Client-Server✔ Stateless✔ Cache? Uniform Interface✔ Layered System

Is This RESTful?

Page 16: All Aboard the Boxcar! Going Beyond the Basics of REST

✔ Identification of resources✔ Manipulation of resources through representations✔ Self-descriptive messages✔ Hypermedia as the engine of application state

What About Uniform Interface?

Page 17: All Aboard the Boxcar! Going Beyond the Basics of REST

POST to /vXX.X/composite/batch{ "batchRequests" : [{ "method" : "PATCH", "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ", "richInput" : {"Name" : "NewName"} },{ "method" : "GET", "url" : "v34.0/sobjects/account/001D000000K0fXOIAZ?fields=Name,LastModifiedDate" }] }

Coalesce independent requestsSolution 2: Batch Requests

Page 18: All Aboard the Boxcar! Going Beyond the Basics of REST

{ "hasErrors" : false, "results" : [{ "statusCode" : 204, "result" : null },{ "statusCode" : 200, "result": { "attributes" : { "type" : "Account", "url" : "/services/data/v34.0/sobjects/Account/001D000000K0fXOIAZ" }, "Name" : "NewName", "LastModifiedDate" : "2015-01-27T20:51:14.000+0000", "Id" : "001D000000K0fXOIAZ" } }] }

Batch Response

Page 19: All Aboard the Boxcar! Going Beyond the Basics of REST

Batch DemoPrinciples in Practice

Page 20: All Aboard the Boxcar! Going Beyond the Basics of REST

✔ Client-Server✔ Stateless✔ Cache? Uniform Interface✔ Layered System

Is This RESTful?

Page 21: All Aboard the Boxcar! Going Beyond the Basics of REST

✔ Identification of resources✔ Manipulation of resources through representations✔ Self-descriptive messages✔ Hypermedia as the engine of application state

Straight JSON via HTTP is just one pattern, not the law!

What About Uniform Interface?

Page 22: All Aboard the Boxcar! Going Beyond the Basics of REST

Go read (or reread!) Fielding’s dissertation…at the very least, read chapter 5!

Follow the REST orthodoxy…until it makes more sense to blaze a new trail…and, even then, check that you’re not driving over a cliff!

Conclusion

Page 23: All Aboard the Boxcar! Going Beyond the Basics of REST

Thank you