HTTP Client Helper Function for Verify Access
Contents
Overview
A HTTP client helper function is a useful tool for simplifying the process of making HTTP requests in your application. With a helper function, you can easily send HTTP requests to a server and receive responses without having to write the low-level code yourself. This can be especially useful when working with APIs or when building applications that need to communicate with other servers over the internet. The helper function can handle all of the details of establishing a connection, sending the request, and parsing the response, allowing you to focus on the task at hand.
A simple, HTTP client helper, leveraging the httpClientHelperV2
class, that can be used throughout mapping rules in Verify Access (or formally known as IBM Security Access Manager (ISAM)).
The httpClientHelperV2()
function simplifies making calls to other API's.
Importing HTTP Client Helper Utils
You can download the mapping rule from GitHub here:
https://github.com/Verify-Access/Utils/tree/main/HTTP%20Client%20Helper
This HTTP Client Helper function requires Logger Utils for the logger()
functions.
To import the mapping rule, simply use:
importMappingRule("httpUtils", "loggerUtils");
Functions
setupInitialHeaders()
Content-Type: application/json
Accept: application/json
authorization()
If authorization is required to access a protected resource, start off by adding the following to your mapping-rule.
httpClientHelperV2.setupInitialHeaders();
httpClientHelperV2.authorization.bearer(" ");
httpClientHelperV2.setupInitialHeaders();
httpClientHelperV2.authorization.basic("username", "password");
Examples
Below are some examples to get started.
GET
result = httpClientHelperV2.httpRequest(GET, "https://accounts.google.com/.well-known/openid-configuration")
POST
jsonClaims = {};
jsonClaims.success = true;
jsonClaims.message = "Successfully completed task"
httpClientHelperV2.setupInitialHeaders();
httpClientHelperV2.authorization.basic("username", "password");
result = httpClientHelperV2.httpRequest(POST, "https://api.server.com/account/ZX123456", jsonClaims)