apex rest webinar - amazon s3s3.amazonaws.com/dfc-wiki/en/images/e/e6/apexrestwebinar.pdf · join...

24
Apex REST API SUMMER OF APIs Sandeep Bhanot Developer Evangelist @cloudysan Alex Toussaint Senior Product Manager @alextoussaint

Upload: others

Post on 17-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST API SUMMER OF APIs

Sandeep Bhanot Developer Evangelist @cloudysan

Alex Toussaint Senior Product Manager @alextoussaint

Page 2: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Got Twitter? @forcedotcom / #forcewebinar

Facebook? facebook.com/forcedotcom

Page 3: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

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 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, 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 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, 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 filed on February 24, 2011 and in other filings with the Securities and Exchange Commission. These documents 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 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 4: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Appetizers Introduction to Apex REST

Common Use Cases

First Course Demo and Code Walkthrough

Second Course Technical Fine Print

Dessert Resources

Q & A

Page 5: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

It’s raining APIs!

REST API Chatter REST API*

Streaming API*

Apex REST API*

* Developer Preview

Page 6: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

What is Apex REST (Developer Preview)?

Expose custom Apex logic as RESTful services.

Force.com

Request

Response

https://na1.salesforce.com/services/apexrest/MyAccountSvc

Page 7: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

It is available now in all DE Orgs

Page 8: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

A Quick REST Primer

Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web

In English…..

  REST = HTTP, Stateless, Uniform Named Resource

  HTTP verb (‘GET’, ‘POST’, ‘PATCH’ etc.) + URI = action.

  Especially popular with Web 2.0/Mobile architectures

Page 9: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST – key characteristics

  Define your own custom Resource URI –  E.g. https://na1.salesforce.com/services/apexrest/MyCustomSvc/v1

  Authentication –  OAuth 2.0 or Session ID (username/password)

  Built in de/serialization support for JSON and XML

  Governor Limits –  Counts against the API request limit for the Org

–  Regular Apex Governor limits apply (e.g. Max. payload size of 3MB)

Page 10: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Comparison with other APIs

Apex REST Apex SOAP REST API SOAP API Bulk API

Protocol REST SOAP/WSDL REST SOAP/ WSDL REST

Data Format JSON/XML/ Custom

XML JSON/XML XML CSV/XML

Client libraries/ tools

HTTP client (lightweight)

SOAP/WSDL library

HTTP client (lightweight)

SOAP/WSDL library

HTTP client (lightweight)

Data Volume Medium Medium Medium Large Very Large

Sync/Async Sync Sync Sync Sync Async

Service Interface

Custom Custom Standard Standard Standard

Page 11: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Common use cases for Apex REST

  Mobile applications –  Custom code to minimize round trips to the server

  Complex transactions –  E.g. Insert Case and child Parts & Labor record(s) in a single

transaction

  Use cases beyond the current REST API –  E.g. Lead Convert, Bulk DML operations

  Custom REST API for your business application –  Reach a broader Web 2.0 developer audience

Page 12: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST early adopters

  Spanning Cloud

WIP - Alex to insert logo and short blurb

Page 13: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST – the basics curl –H “Authorization: OAuth <Session ID>” “https://<instance>.salesforce.com/services/apexrest/MyAccountSvc/0015000000WU3vC”

Page 14: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Demo Time: ‘Find Nearby Cases’ on Android

Page 15: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST Annotations

Annotation Description Incoming Data @RestResource (urlMapping=‘<your URL>’)

Defines the class as a custom Apex endpoint.

None

@HttpGet Defines the function to be used with the endpoint with HTTP GET

Query Parameters

@HttpDelete Defines the function to be used with the endpoint with HTTP DELETE

Query Parameters

@HttpPost Defines the function to be used with the endpoint with HTTP POST

POST Data in JSON or XML

@HttpPatch Defines the function to be used with the endpoint with HTTP PATCH

POST Data in JSON or XML

@HttpPut Defines the function to be used with the endpoint with HTTP PUT

POST Data in JSON or XML

Page 16: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Key considerations for Apex REST (Provider)

Supported return types and parameter types: •  Apex primitives •  SObjects •  List or Maps of the first two types

Use ‘with sharing’ in the Apex REST class to respect data security

Use RestRequest and RestResponse classes instead of, or in addition to, method parameters and return types

Page 17: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Key considerations for Apex REST (Consumer)

URL mapping relative to https://<instance>.salesforce.com/services/apexrest/...

The ‘Content-Type’ header set by the client determines JSON vs. XML format (JSON is the default)

If your client HTTP library does not support ‘PATCH’, use POST and add the ‘?_HttpMethod=PATCH’ query param to the Request URI

Page 18: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Apex REST Service

Sample JSON Request

Key considerations for Apex REST (Consumer)

  The name and order of the method parameters matter –  Use a JSON library that respects the element order (e.g.

http://code.google.com/p/json-simple/ for Java)

Parameter names are case sensitive

Parameter order has to be maintained in the

JSON/XML request data

Null/blank values have to be included for

optional parameters

Page 19: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

  Use to access request/response HTTP headers, cookies etc.

  Use if you don’t want the platform to perform automatic serialization/de-serialization of the request/response data

The RestRequest and RestReponse classes

Page 20: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

  REST URI naming best practices •  Add versioning in the URI

  Use ‘with sharing’ to respect data security rules

  Enable access for the Apex REST service Class for all User Profiles that will invoke the service

  ‘Bulkify’ the service code to minimize traffic (and save API calls)

Apex REST best practices

Page 21: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Resources

  Landing page –  http://developer.force.com/REST

  Apex REST Developer’s guide –  http://www.salesforce.com/us/developer/docs/apex_rest/api_apex_rest.pdf

  Introducing Apex REST services –  article

  Using Node.js with Apex REST –  http://blogs.developerforce.com/developer-relations/2011/06/using-nodejs-with-forcecom.html

  Apex REST sample from the Summer 11 webinar –  http://blog.sforce.com/sforce/2011/05/apex-rest-services-in-summer-11.html

  Discussion Boards (REST Development) –  http://boards.developerforce.com/t5/REST-API-Integration/bd-p/integration

Page 22: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Sessions at Dreamforce 2011

  What's New in the Force.com REST API

Page 23: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

http://bit.ly/ApexRest7am

Page 24: Apex REST Webinar - Amazon S3s3.amazonaws.com/dfc-wiki/en/images/e/e6/ApexRESTWebinar.pdf · Join the conversation on Twitter: #forcewebinar @forcedotcom Comparison with other APIs

Join the conversation on Twitter: #forcewebinar @forcedotcom

Questions?