HTTPClient Object
Last updated 2/04/2024
To create an instance of the HTTPClient
object, you call the httpClient()
function provided by the Five
object to instantiate an instance of the HTTPClient
object. This
provides many ways to interact with existing web content using the Hypertext Transfer Protocol (HTTP), or the built-in headless web browser. HTTP is designed to
enable communications between clients and servers working as a request-response protocol between a client and server for fetching resources such as HTML documents.
For example, a client (browser) sends a HTTP request to the server, the server then responds to the client with the response that contains status information about the request.
Five provides two modes to interact with an external API.
- RAW - This is straight text or JSON from the server.
- BROWSER - This is a full headless web browser session.
Functions
The following functions can used on the HTTPClient
object.
addData()
The addData()
is a function on the HTTPClient
object that adds a key value pair to the body of the POST
request, or as URL encoded URL parameters for a GET
request when using RAW mode for the get()
and post()
methods and returns null
on success.
addData(name: string, value: string) : FiveError;
get()
The get()
is a function on the HTTPClient
object that is used to request data from a specific resource.
get([mode: string,] url: string) : HTTPResponse | BrowserPage;
addHeader()
The addHeader()
is a function on the HTTPClient
object that will let the client and the server pass additional information with a HTTP request or response.
addHeader(name: string, value: string) : FiveError;
post()
The post()
is a function on the HTTPClient
object that is used to send data to the server to create/update a resource.
post([mode: string,] url: string) : HTTPResponse | BrowserPage;
setBasicAuthentication ()
The setBasicAuthentication()
is a function on the HTTPClient
object that sets the basic authentication header for the request.
setBasicAuthentication(user: string, password: string) : FiveError;
setContent()
The setContent()
is a function on the HTTPClient
object to set the contents of the request body.
setContent(contents: string) : FiveError;
setContentType()
The setContentType()
is a function on the HTTPClient
object that is used to indicate the original media type of the contents.
setContentType(mimeType: string) : FiveError;