A small library to make building HttpRequest
instances in Apex easy.
new HttpRequestBuilder()
.post('https://www.example.com')
.json(new Account(Name = 'Example'))
.send()
A POST request will be sent to https://www.example.com
with the Content-Type
header set to application/json
and the Account serialized as JSON in the body.
HttpRequest build()
Build a new client request.
HttpRequest build(List<String> params)
Build a new client request with the given parameters substituted within the endpoint.
HttpResponse send()
Sends the request and returns the response.
HttpResponse send(List<String> params)
Sends the request with the given parameters substituted within the endpoint and returns the response.
HttpRequestBuilder get(String endpoint)
Sets the type of method to be used for the HTTP request to GET and specifies the endpoint for this request.
HttpRequestBuilder patch(String endpoint)
Sets the type of method to be used for the HTTP request to PATCH and specifies the endpoint for this request.
HttpRequestBuilder post(String endpoint)
Sets the type of method to be used for the HTTP request to POST and specifies the endpoint for this request.
HttpRequestBuilder put(String endpoint)
Sets the type of method to be used for the HTTP request to PUT and specifies the endpoint for this request.
HttpRequestBuilder json(Object data)
Sets the contents of the body for this request. The contents are serialized as JSON.
HttpRequestBuilder setBody(String body)
Sets the contents of the body for this request.
HttpRequestBuilder setBody(Blob body)
Sets the contents of the body for this request using a Blob.
HttpRequestBuilder setBody(Dom.Document document)
Sets the contents of the body for this request. The contents represent a DOM document.
HttpRequestBuilder setClientCertificateName(String certDevName)
If the external service requires a client certificate for authentication, set the certificate name.
HttpRequestBuilder setCompressed(Boolean flag)
If true, the data in the body is delivered to the endpoint in the gzip compressed format. If false, no compression format is used.
HttpRequestBuilder setEndpoint(String endpoint)
Specifies the endpoint for this request.
HttpRequestBuilder setHeader(String key, String value)
Sets the contents of the request header.
HttpRequestBuilder setHeaders(Map<String, String> headers)
Sets the contents of multiple request headers.
HttpRequestBuilder setMethod(String method)
Sets the type of method to be used for the HTTP request.
HttpRequestBuilder setTimeout(Integer timeout)
Sets the timeout in milliseconds for the request.