Skip to content

Configuration methods ​

Before calling any HTTP/HTTPS verb to make the HttpCli perform a request, you must first create and configure the object according to your needs. This includes specifying the URL, request body, headers, timeout, and any authentication or other options required for your call.

The HttpCli object is highly flexible. For example, you might create and configure it as follows:

ts
// Create HttpCli object
var hc = new HttpCli();
// Configure the hc object as needed...

Below are the available configuration methods:

Url ​

ts
hc.Url(fullyQualifiedUrl: string): HttpCli;

Required. Sets the full URL for the HTTP/HTTPS request. Only the most recent call to .Url() is used.

Accept ​

ts
hc.Accept(contentType: string): HttpCli;

Sets the expected MIME type for the server response. Only the most recent call to .Accept() is used.

ApiKey ​

ts
hc.ApiKey(yourApiKey: string): HttpCli;

Sets an API key for authentication. Only the most recent call to .ApiKey() is used.

BasicAuth ​

ts
hc.BasicAuth(username: string, password: string): HttpCli;

Sets HTTP Basic Authentication credentials. Only the most recent call to .BasicAuth() is used.

Bearer ​

ts
hc.Bearer(bearerToken: string): HttpCli;

Sets a Bearer Token for authentication. Only the most recent call to .Bearer() is used.

FormField ​

ts
hc.FormField(fieldName: string, fieldValue: string): HttpCli;

Adds a form field to a multipart/form-data request body (typically for POST requests). This method is additive—call it multiple times to add multiple fields.

ts
hc.Header(headerName: string, headerValue: string): HttpCli;

Adds a custom header to the request. This method is additive—call it multiple times to add multiple headers.

InsecureSkipVerify ​

ts
hc.InsecureSkipVerify(): HttpCli;

Accepts any server certificate, including self-signed certificates, when making HTTPS requests. Use with caution.

ReqBody ​

ts
hc.ReqBody(body: string): HttpCli;

Sets the raw request body. If the string is valid JSON, the Content-Type header is automatically set to application/json. Only the most recent call to .ReqBody() is used.

Timeout ​

ts
hc.Timeout(seconds: number): HttpCli;

Sets the request timeout in seconds. Only the most recent call to .Timeout() is used.

UserAgent ​

ts
hc.UserAgent(softwareId: string): HttpCli;

Sets a custom User-Agent header. Only the most recent call to .UserAgent() is used.

NOTE

For methods that are additive (such as .FormField() and .Header()), each call adds a new value. For all others, only the most recent value is used.