Http global virtual inherited sharing class
Http Description A utility class for making HTTP callouts. Get, Post, Put, Patch, and Delete methods are supported.
Usage:
// Do a simple HTTP GET callout
String result = new aBoost.Http('https://httpbin.org/get').get();
// Do a POST callout using a named credential with a body
MyResult result = (MyResult)new aBoost.Http('callout:SapService/order')
.setBody(myFormContents)
.post(MyResult.class);
request global HttpRequest request
The request can be used independently or added to a Continuation
Constructors Description Construct an Http object with the specified endpoint Parameter endpoint: the URL or Named Credential Throws InvalidParameterValueException if endpoint is blank
Methods Description Do an HTTP DELETE callout Returns the response body Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE
global Object del(
Type returnType)
Description Do an HTTP DELETE callout Returns the response, converted to 'returnType', if not null Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE Throws JSONException if the result cannot be converted to 'returnType'
Description Do an HTTP GET callout Returns the response body Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE
global Object get(
Type returnType)
Description Do an HTTP GET callout Returns the response, converted to 'returnType', if not null Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE Throws JSONException if the result cannot be converted to 'returnType'
Description Do an HTTP PATCH callout Returns the response body Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE
global Object patch(
Type returnType)
Description Do an HTTP PATCH callout Returns the response, converted to 'returnType', if not null Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE Throws JSONException if the result cannot be converted to 'returnType'
Description Do an HTTP POST callout Returns the response body Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE
global Object post(
Type returnType)
Description Do an HTTP POST callout Returns the response, converted to 'returnType', if not null Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE Throws JSONException if the result cannot be converted to 'returnType'
Description Do an HTTP PUT callout Returns the response body Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE
global Object put(
Type returnType)
Description Do an HTTP PUT callout Returns the response, converted to 'returnType', if not null Throws CalloutException on an HTTP status code < SUCCESS or >= FAILURE Throws JSONException if the result cannot be converted to 'returnType'
global
Http setBody(Object body)
Description Set the body to be sent. The body may be a String , Blob , or other serializable object Throws InvalidParameterValueException if body is null
Description In cases where the external service requires a client certificate for authentication, set the name of the client certificate Throws InvalidParameterValueException if certName is blank
Description If true, the data in the body is delivered to the endpoint in the gzip compressed format Throws InvalidParameterValueException if compressed is null
Description Set a header key and value to be sent Throws InvalidParameterValueException if key is null
Description Set a query parameter key and value to be sent
Description Set a custom timeout value (in milliseconds) Throws InvalidParameterValueException if timeout is null or negative
Http.Mock global class Mock implements HttpCalloutMock
Description an HttpCalloutMock implementation for testing web service callouts Can handle multiple endpoints, multiple methods per instance, and multiple responses per endpoint/method
Usage:
// test simple callout (will be used for all callouts in the transaction)
aBoost.Http.mock(new aBoost.Http.Mock('b1'));
... // run Apex that performs callouts and validate results
// test several different callouts (each will be used only once)
Mock m = new aBoost.Http.Mock('GET', 'https://google.com', 'b1');
m.add('GET', 'https://google.com', 'b1'); // test second GET callout
m.add('PUT', 'https://google.com', 'b3'); // test PUT to Google
m.add('GET', 'https://amazon.com', 'b4', aBoost.Http.FAILURE); // test GET callout to Amazon
aBoost.Http.mock(m);
... // run Apex that performs callouts and validate results
Methods global void add(
String method,
String endpoint, Object body)
Description Add a successful callout mock for a specific method and endpoint Throws InvalidParameterValueException if method or endoint is blank
Description Add a callout mock for a specific method and endpoint Throws InvalidParameterValueException if method or endoint is blank, or status is null
global Mock(Object body)
Description Construct a single, successful callout mock that will be used for all callouts in the transaction
global Mock(Object body,
Integer status)
Throws InvalidParameterValueException if status is null
Description Construct a successful callout mock for a specific method and endpoint; call 'add' to specify mocks for additional callouts Throws InvalidParameterValueException if method or endoint is blank
Description Construct a callout mock for a specific method and endpoint; call 'add' to specify mocks for additional callouts Throws InvalidParameterValueException if method or endoint is blank, or status is null