Skip to content

UTIL_HttpClient

Class · Group: Web Services

apex
global inherited sharing class UTIL_HttpClient

Fluent HTTP client facade over the API_Dispatcher pipeline. Provides zero-boilerplate callouts with automatic retry, circuit breaker, failure logging, performance timing, sensitive data masking, and ApiCall__c lifecycle management — all routed through API_Dispatcher.execute(). Supports two usage modes: Ad-hoc mode: Direct HTTP calls via get()/post()/put()/del()/patch() entry points Delegation mode: Subscriber handlers via useHandler() entry point

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.post('PaymentGateway', '/charges')
   .body(chargeRequest)
   .withRetry(3)
   .send();

Properties

PropertyDescription
global enum FailureActionDefines the action to take when an HTTP call fails.

Methods

MethodDescription
global static UTIL_HttpClient.RequestBuilder del(String credential, String path)Creates a DELETE request for the specified credential and path.
global static UTIL_HttpClient.RequestBuilder get(String credential, String path)Creates a GET request for the specified credential and path.
global static UTIL_HttpClient.RequestBuilder patch(String credential, String path)Creates a PATCH request for the specified credential and path.
global static UTIL_HttpClient.RequestBuilder post(String credential, String path)Creates a POST request for the specified credential and path.
global static UTIL_HttpClient.RequestBuilder put(String credential, String path)Creates a PUT request for the specified credential and path.
global static UTIL_HttpClient.RequestBuilder useHandler(Type handlerType)Creates a delegation mode request for the specified subscriber handler.

Inner Classes

ClassDescription
RequestBuilderFluent builder for configuring and executing HTTP requests through API_Dispatcher.

Method Details

del

apex
global static UTIL_HttpClient.RequestBuilder del(String credential, String path)

Creates a DELETE request for the specified credential and path.

Parameters:

  • credential (String) - The Named Credential or ApiCredential__mdt DeveloperName
  • path (String) - The URL path to append to the endpoint

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder for further configuration

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.del('CRM', '/contacts/{id}')
   .pathParam('id', contactId)
   .send();

get

apex
global static UTIL_HttpClient.RequestBuilder get(String credential, String path)

Creates a GET request for the specified credential and path.

Parameters:

  • credential (String) - The Named Credential or ApiCredential__mdt DeveloperName
  • path (String) - The URL path to append to the endpoint

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder for further configuration

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.get('CRM', '/accounts/{id}')
   .pathParam('id', accountId)
   .send();

patch

apex
global static UTIL_HttpClient.RequestBuilder patch(String credential, String path)

Creates a PATCH request for the specified credential and path.

Parameters:

  • credential (String) - The Named Credential or ApiCredential__mdt DeveloperName
  • path (String) - The URL path to append to the endpoint

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder for further configuration

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.patch('CRM', '/contacts/{id}')
   .pathParam('id', contactId)
   .body(patchPayload)
   .send();

post

apex
global static UTIL_HttpClient.RequestBuilder post(String credential, String path)

Creates a POST request for the specified credential and path.

Parameters:

  • credential (String) - The Named Credential or ApiCredential__mdt DeveloperName
  • path (String) - The URL path to append to the endpoint

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder for further configuration

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.post('EmailService', '/send')
   .body(emailPayload)
   .send();

put

apex
global static UTIL_HttpClient.RequestBuilder put(String credential, String path)

Creates a PUT request for the specified credential and path.

Parameters:

  • credential (String) - The Named Credential or ApiCredential__mdt DeveloperName
  • path (String) - The URL path to append to the endpoint

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder for further configuration

Since: 1.0

Example:

apex
HttpResponse response = UTIL_HttpClient.put('CRM', '/contacts/{id}')
   .pathParam('id', contactId)
   .body(contactPayload)
   .send();

useHandler

apex
global static UTIL_HttpClient.RequestBuilder useHandler(Type handlerType)

Creates a delegation mode request for the specified subscriber handler.

Parameters:

  • handlerType (Type) - The API_Outbound subclass Type to delegate to

Returns: UTIL_HttpClient.RequestBuilder - A RequestBuilder configured for delegation mode

Since: 1.0

Example:

apex
API_Outbound handler = UTIL_HttpClient.useHandler(API_SendEmail.class)
   .credential('EmailGateway')
   .withParameter(API_SendEmail.PARAM_RECIPIENT, email)
   .invoke();