-
Notifications
You must be signed in to change notification settings - Fork 422
ApiServiceRecipes
This recipe extends the custom RestClient class and represents a specific REST API service we need to interact with - in this case the Google Books API. This class is responsible for serializing and deserializing the Data Transfer Objects (Model Objects) necessary for input and output from this org to the third party system and back. More on the Google Books API here: https://developers.google.com/books/docs/v1/reference/volumes
Inheritance
RestClient > ApiServiceRecipes
Group Integration Recipes
See RestClient
See ApiServiceRecipesDataModel
default constructor. Sets the inherited named credential to the DEFAULTNAMEDCREDENTIAL constant above. Setting the namedCredentialName binds all the methods in this class to the specific namedCredential URL and auth.
TESTVISIBLE
Inherited
TESTVISIBLE
The name of the Named Credential to use
Encapsulates a specific callout to the Named Credential URL that returns JSON into an method that transforms the raw JSON into an Apex Object.
Type | Description |
---|---|
List<ApiServiceRecipesDataModel> |
List<ApiServiceRecipesDataModel> |
ApiServiceRecipes asr = new ApiServiceRecipes();
System.debug(asr.getCurrentData());
protected HttpResponse makeApiCall(HttpVerb method, String path, String query, String body, Map<String,String> headers)
Inherited
TESTVISIBLE
SUPPRESSWARNINGS
Omnibus callout method. This is the primary method for making a REST callout. Most of the other methods in this class serve as convient, syntactic sugar on this method.
Param | Description |
---|---|
method |
Enum HTTP verb to use. i.e. GET |
path |
patch component of the callout url i.e. /services/data/v39.0/SObjects
|
query |
Query portion of the URL i.e. ?q=SELECT Id FROM Account
|
body |
JSON string representing the body of the callout in post/patch situations |
headers |
A map<String,String> of headers to use while making this callout |
Type | Description |
---|---|
HttpResponse |
HttpResponse HttpResponse Obj |
Inherited
TESTVISIBLE
SUPPRESSWARNINGS
Makes an HTTP Callout to an api resource. Convienence method that assumes the Default Headers.
Param | Description |
---|---|
method |
HTTPVerb to use. See the enum above. |
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
body |
Body to send with this call. |
Type | Description |
---|---|
HttpResponse |
HttpResponse |
Inherited
TESTVISIBLE
convenience version of makeApiCall without body param. Invokes omnibus version above, with blank body param and default headers.
Param | Description |
---|---|
method |
HTTPVerb to use. See the enum above. |
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience version of makeApiCall without body or query params. Invokes omnibus version above, with blank body and query params
Param | Description |
---|---|
method |
HTTPVerb to use. See the enum above. |
path |
Http path component of the URL. ie: /path/to/resource
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a GET Call that only requires a path
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a GET Call that only requires a path and query
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for deleteing a resource based only on path
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a Delete Call that only requires a path and query
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a POST Call that only requires a path and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a POST Call that only requires a path, query and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a PUT Call that only requires a path and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a PUT Call that only requires a path, query and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a PATCH Call that only requires a path, query and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
convenience method for a PATCH Call that only requires a path, query and body
Param | Description |
---|---|
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
body |
JSON string to post |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
Inherited
TESTVISIBLE
Ensures that the inputted string ends in a /
makes callouts more robust.
Param | Description |
---|---|
resource |
string to ensure ends in /
|
Type | Description |
---|---|
String |
inputted string with / if it didn't already end in one. |
public static HttpResponse makeApiCall(String namedCredential, HttpVerb method, String path, String query, String body, Map<String,String> headers)
Inherited
SUPPRESSWARNINGS
A static wrapper for the main makeApiCall method
Param | Description |
---|---|
namedCredential |
The named credential to use |
method |
HTTPVerb enum value. See Enum above |
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
body |
JSON string to post |
headers |
Map<String,String> representing outgoing Request headers |
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes',
'q=salesforce',
'',
new Map<String,String>()));
public static HttpResponse makeApiCall(String namedCredential, HttpVerb method, String path, String query)
Inherited
SUPPRESSWARNINGS
A static wrapper for the main makeApiCall method that assumes default headers.
Param | Description |
---|---|
namedCredential |
The named credential to use |
method |
HTTPVerb enum value. See Enum above |
path |
Http path component of the URL. ie: /path/to/resource
|
query |
Query component of the URL ie: after ?foo=bar
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes',
'q=salesforce'));
Inherited
A static wrapper for the main makeApiCall method where you only need the path
Param | Description |
---|---|
namedCredential |
The named credential to use |
method |
HTTPVerb enum value. See Enum above |
path |
Http path component of the URL. ie: /path/to/resource
|
Type | Description |
---|---|
HttpResponse |
HTTPResponse |
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes'));
Internal custom exception used by this class for errors
Inheritance
ApiException