HttpCli configuration methods

Before you call any of the http/https verbs to actually make the HttpCli do something, you must first create the object and configure it according to what you actually intend it to do. This means, for example, specifying the URL you want to call, or the request body you want to send to such URL, or even a timeout past which you want this call to give up.

The HttpCli object is quite flexible in these regards; let’s assume you’ve created your object like this:

{
  // create HttpCli object, let's call it "hc"
  var hc = new HttpCli();
  // time to configure our "hc" object...
  // ...
  // ...
}

Then, all the configuration methods are as follows:

hc.Url(fullyQualifiedUrl: string): HttpCli

This configuration is mandatory, every time you want to perform an http/https call, you have to set the URL property, which is the full address of the web resource you’re addressing your call to (ex: hc.Url("https://www.example.com")). Calling with method more than once will substitute the previous URL, so only the most recent call to .Url() will be considered.

hc.Accept(contentType: string): HttpCli

You may set this configuration if you want your HttpCli to only accept from the server a response that has a certain MIME-type. Calling with method more than once will substitute the previous value of Accept, so only the most recent call to .Accpet() will be considered.

hc.ApiKey(yourApiKey: string): HttpCli

If the server requires an API Key to serve a certain resource, you may specify such API Key using this method. Calling with method more than once will substitute the previous value of ApiKey, so only the most recent call to .ApiKey() will be considered.

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

If the server requires basic authentication to serve a certain resource, you may specify username and password using this method. Calling with method more than once will substitute the previous value of BasicAuth, so only the most recent call to .BasicAuth() will be considered.

hc.Bearer(bearerToken: string): HttpCli

If the server requires a Bearer Token to serve a certain resource, you may specify such Bearer Token using this method. Calling with method more than once will substitute the previous value of the Bearer Token, so only the most recent call to .Bearer() will be considered.

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

If you want to send your request body with a multipart/form in it (typical with POST request), you may call this method to add a form field and its value to the request body payload. This call is additive, so you can call .FormField() multiple times to add multiple form fields and values.

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

If you want to send your http/https request with additional headers in it, you may call this method to add a header and its value to the request itself before it is sent to the server. This call is additive, so you can call .Header() multiple times to add multiple headers to the outgoing http/https call.

hc.InsecureSkipVerify(): HttpCli

Adding .InsecureSkipVerify() to your object configuration instructs the client to accept any server certificate, even self-signed ones, when performing https:// requests.

hc.ReqBody(body: string): HttpCli

This mathod allows you to specify the raw body payload to be sent with this request; if the string you pass to it is recognized as a valid JSON structure, the HttpCli object will also automatically add/set the Content-Type header to application/json. Calling with method more than once will substitute the previous body payload, so only the most recent call to .ReqBody() will be considered.

hc.Timeout(seconds: number): HttpCli

This simply sets a timeout past which HttpCli will give up if it hasn’t received a response from the server yet. Calling with method more than once will substitute the previous timeout value, so only the most recent call to .Timeout() will be considered.

hc.UserAgent(softwareId: string): HttpCli

This method allows you to set a custom User-Agent for your http/https call. Calling with method more than once will substitute the previous user agent value, so only the most recent call to .UserAgent() will be considered.