# UTIL_HttpClient

**Class** · Group: `Web Services`

Learn it: [Fast Start - Outbound APIs](/fast-start-outbound-apis) and [Web Services guide](/web-services-guide)

<div class="apex-member apex-class">

```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: your own handler classes via useHandler() entry point

**Example**

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

</div>

---

## Methods

| Method | Description |
|--------|-------------|
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [del](#del)([String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) credential, [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) path) | Creates a DELETE request for the specified credential and path. |
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [get](#get)([String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) credential, [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) path) | Starts a request that reads data. |
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [patch](#patch)([String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) credential, [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) path) | Starts a request that changes part of a resource, usually with body(...). |
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [post](#post)([String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) credential, [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) path) | Starts a request that sends new data, usually with body(...). |
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [put](#put)([String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) credential, [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) path) | Starts a request that replaces a resource, usually with body(...). |
| global static [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) [useHandler](#usehandler)([Type](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_type.htm) handlerType) | Creates a delegation mode request for the specified handler class of your own. |

### del

<div class="apex-member">

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

Creates a DELETE request for the specified credential and path.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `credential` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The Named Credential or ApiCredential__mdt DeveloperName |
| `path` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The URL path to append to the endpoint |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder for further configuration

**Example**

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

</div>

### get

<div class="apex-member">

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

Starts a request that reads data. Nothing is sent until you call send() on the builder. The path is
added to the credential's endpoint, and it can hold {name} placeholders that pathParam fills in.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `credential` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The Named Credential or ApiCredential__mdt DeveloperName |
| `path` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The URL path to append to the endpoint |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder for further configuration

**Example**

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

</div>

### patch

<div class="apex-member">

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

Starts a request that changes part of a resource, usually with body(...). Nothing is sent until you call
send() on the builder. With retries turned on and no retryOn list, a PATCH that carries no idempotency key (the key
you give withIdempotencyKey so the other system can recognise a repeat) is not sent again after a 500, 502 or 504,
because the other system may already have acted on it.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `credential` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The Named Credential or ApiCredential__mdt DeveloperName |
| `path` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The URL path to append to the endpoint |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder for further configuration

**Example**

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

</div>

### post

<div class="apex-member">

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

Starts a request that sends new data, usually with body(...). Nothing is sent until you call send() on
the builder. With retries turned on and no retryOn list, a POST that carries no idempotency key (the key you give
withIdempotencyKey so the other system can recognise a repeat) is not sent again after a 500, 502 or 504, because
the other system may already have acted on it.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `credential` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The Named Credential or ApiCredential__mdt DeveloperName |
| `path` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The URL path to append to the endpoint |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder for further configuration

**Example**

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

</div>

### put

<div class="apex-member">

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

Starts a request that replaces a resource, usually with body(...). Nothing is sent until you call send()
on the builder. With retries turned on and no retryOn list, a PUT counts as safe to repeat, so it is sent again
after a 500, 502 or 504.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `credential` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The Named Credential or ApiCredential__mdt DeveloperName |
| `path` | [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm) | The URL path to append to the endpoint |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder for further configuration

**Example**

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

</div>

### useHandler

<div class="apex-member">

```apex
global static UTIL_HttpClient.RequestBuilder useHandler(Type handlerType)
```

Creates a delegation mode request for the specified handler class of your own. Your handler's inputs also
carry three keys that hold the retry values of withRetry and withExponentialBackoff: `__exponentialBackoff`,
`__maxRetries` and `__backoffSeconds`. Leave them in place, the framework reads them on every run.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `handlerType` | [Type](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_type.htm) | The API_Outbound subclass Type to delegate to |

**Returns** [UTIL_HttpClient.RequestBuilder](/reference/apex/util-httpclient-requestbuilder) — A RequestBuilder configured for delegation mode

**Example**

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

</div>

## Inner Classes

| Class | Description |
|-------|-------------|
| [FailureAction](/reference/apex/util-httpclient-failureaction) | Defines the action to take when an HTTP call fails. |
| [RequestBuilder](/reference/apex/util-httpclient-requestbuilder) | Fluent builder for configuring and executing HTTP requests through API_Dispatcher. |

---
