Apex BOOST Library
v1.7 from Lucidware Solutions (LWS)

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);
 

  Properties

request
global HttpRequest request
The request can be used independently or added to a Continuation

Constructors

  Http

global Http(String endpoint)
DescriptionConstruct an Http object with the specified endpoint
Parameterendpoint: the URL or Named Credential
ThrowsInvalidParameterValueException if endpoint is blank

Methods

  del

global String del()
DescriptionDo an HTTP DELETE callout
Returnsthe response body
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE

  del

global Object del(Type returnType)
DescriptionDo an HTTP DELETE callout
Returnsthe response, converted to 'returnType', if not null
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE
ThrowsJSONException if the result cannot be converted to 'returnType'

  get

global String get()
DescriptionDo an HTTP GET callout
Returnsthe response body
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE

  get

global Object get(Type returnType)
DescriptionDo an HTTP GET callout
Returnsthe response, converted to 'returnType', if not null
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE
ThrowsJSONException if the result cannot be converted to 'returnType'

  patch

global String patch()
DescriptionDo an HTTP PATCH callout
Returnsthe response body
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE

  patch

global Object patch(Type returnType)
DescriptionDo an HTTP PATCH callout
Returnsthe response, converted to 'returnType', if not null
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE
ThrowsJSONException if the result cannot be converted to 'returnType'

  post

global String post()
DescriptionDo an HTTP POST callout
Returnsthe response body
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE

  post

global Object post(Type returnType)
DescriptionDo an HTTP POST callout
Returnsthe response, converted to 'returnType', if not null
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE
ThrowsJSONException if the result cannot be converted to 'returnType'

  put

global String put()
DescriptionDo an HTTP PUT callout
Returnsthe response body
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE

  put

global Object put(Type returnType)
DescriptionDo an HTTP PUT callout
Returnsthe response, converted to 'returnType', if not null
ThrowsCalloutException on an HTTP status code < SUCCESS or >= FAILURE
ThrowsJSONException if the result cannot be converted to 'returnType'

  setBody

global Http setBody(Object body)
DescriptionSet the body to be sent. The body may be a String, Blob, or other serializable object
ThrowsInvalidParameterValueException if body is null

  setCertName

global Http setCertName(String certName)
DescriptionIn cases where the external service requires a client certificate for authentication, set the name of the client certificate
ThrowsInvalidParameterValueException if certName is blank

  setCompressed

global Http setCompressed(Boolean compressed)
DescriptionIf true, the data in the body is delivered to the endpoint in the gzip compressed format
ThrowsInvalidParameterValueException if compressed is null

  setHeader

global Http setHeader(String key, String value)
DescriptionSet a header key and value to be sent
ThrowsInvalidParameterValueException if key is null

  setParam

global Http setParam(String key, Object value)
DescriptionSet a query parameter key and value to be sent

  setTimeout

global Http setTimeout(Integer timeout)
DescriptionSet a custom timeout value (in milliseconds)
ThrowsInvalidParameterValueException if timeout is null or negative

Http.Mock

global class Mock implements HttpCalloutMock
Descriptionan 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

  add

global void add(String method, String endpoint, Object body)
DescriptionAdd a successful callout mock for a specific method and endpoint
ThrowsInvalidParameterValueException if method or endoint is blank

  add

global void add(String method, String endpoint, Object body, Integer status)
DescriptionAdd a callout mock for a specific method and endpoint
ThrowsInvalidParameterValueException if method or endoint is blank, or status is null

  Mock

global Mock(Object body)
DescriptionConstruct a single, successful callout mock that will be used for all callouts in the transaction

  Mock

global Mock(Object body, Integer status)
ThrowsInvalidParameterValueException if status is null

  Mock

global Mock(String method, String endpoint, Object body)
DescriptionConstruct a successful callout mock for a specific method and endpoint; call 'add' to specify mocks for additional callouts
ThrowsInvalidParameterValueException if method or endoint is blank

  Mock

global Mock(String method, String endpoint, Object body, Integer status)
DescriptionConstruct a callout mock for a specific method and endpoint; call 'add' to specify mocks for additional callouts
ThrowsInvalidParameterValueException if method or endoint is blank, or status is null