Skip to main content

API Reference

Classes ​

Http ​

The Http class is used for calling different HTTP methods and requesting and sending information online, as well as testing public accessible resources.

Static Functions ​

NameDescription
connect
Executes a CONNECT request to a specified URL and provides a formatted response.
delete
Executes a DELETE request to a specified URL and provides a formatted response.
fetch
Executes a HTTP request to a specified URL and provides a formatted response.
formatUrl
Serializes an URL Struct to a String.
get
Executes a GET request to a specified URL and provides a formatted response.
parseUrl
Parses the input URL String using WHATWG URL API and returns an URL Struct.
patch
Executes a PATCH request to a specified URL and provides a formatted response.
post
Executes a POST request to a specified URL and provides a formatted response.
put
Executes a PUT request to a specified URL and provides a formatted response.
trace
Executes a TRACE request to a specified URL and provides a formatted response.

connect ​
bring http;

inflight http.connect(url: str, options?: RequestOptions);

Executes a CONNECT request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the CONNECT request.


optionsOptional ​

Optional parameters for customizing the CONNECT request.


delete ​
bring http;

inflight http.delete(url: str, options?: RequestOptions);

Executes a DELETE request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the DELETE request.


optionsOptional ​

Optional parameters for customizing the DELETE request.


fetch ​
bring http;

inflight http.fetch(url: str, options?: RequestOptions);

Executes a HTTP request to a specified URL and provides a formatted response.

This method allows various HTTP methods based on the provided options.

urlRequired ​
  • Type: str

The target URL for the request.


optionsOptional ​

Optional parameters for customizing the HTTP request.


formatUrl ​
bring http;

inflight http.formatUrl(url: Url, options?: FormatUrlOptions);

Serializes an URL Struct to a String.

urlRequired ​

The URL Struct to be formatted.


optionsOptional ​

get ​
bring http;

inflight http.get(url: str, options?: RequestOptions);

Executes a GET request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the GET request.


optionsOptional ​

Optional parameters for customizing the GET request.


parseUrl ​
bring http;

inflight http.parseUrl(urlString: str);

Parses the input URL String using WHATWG URL API and returns an URL Struct.

urlStringRequired ​
  • Type: str

The URL String to be parsed.


patch ​
bring http;

inflight http.patch(url: str, options?: RequestOptions);

Executes a PATCH request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the PATCH request.


optionsOptional ​

Optional parameters for customizing the PATCH request.


post ​
bring http;

inflight http.post(url: str, options?: RequestOptions);

Executes a POST request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the POST request.


optionsOptional ​

Optional parameters for customizing the POST request.


put ​
bring http;

inflight http.put(url: str, options?: RequestOptions);

Executes a PUT request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the PUT request.


optionsOptional ​

ptional parameters for customizing the PUT request.


trace ​
bring http;

inflight http.trace(url: str, options?: RequestOptions);

Executes a TRACE request to a specified URL and provides a formatted response.

urlRequired ​
  • Type: str

The target URL for the TRACE request.


optionsOptional ​

Optional parameters for customizing the TRACE request.


Structs ​

FormatUrlOptions ​

Options for serializing a WHATWG URL to a String.

Initializer ​

bring http;

let FormatUrlOptions = http.FormatUrlOptions{ ... };

Properties ​

NameTypeDescription
auth
boolWhether the formatted URL should include the username and password.
fragment
boolWhether the formatted URL should include the fragment identifier.
search
boolWhether the formatted URL should include the search query.
unicode
boolWhether the formatted URL should represent Unicode characters for the host component.

authOptional ​
auth: bool;
  • Type: bool

Whether the formatted URL should include the username and password.


fragmentOptional ​
fragment: bool;
  • Type: bool

Whether the formatted URL should include the fragment identifier.


searchOptional ​
search: bool;
  • Type: bool

Whether the formatted URL should include the search query.


unicodeOptional ​
unicode: bool;
  • Type: bool

Whether the formatted URL should represent Unicode characters for the host component.


RequestOptions ​

An object containing any custom settings that you want to apply to the request.

Initializer ​

bring http;

let RequestOptions = http.RequestOptions{ ... };

Properties ​

NameTypeDescription
body
strAny body that you want to add to your request.
cache
RequestCache
The cache mode you want to use for the request.
headers
MutMap<str>Any headers you want to add to your request.
method
HttpMethod
The request method, e.g., GET, POST. The default is GET.
redirect
RequestRedirect
An enum specifying the redirect mode to use: follow, error or manual.
referrer
strA string specifying "no-referrer", client, or a URL.
timeout
duration
Timeout for terminating a pending request.

bodyOptional ​
body: str;
  • Type: str

Any body that you want to add to your request.

Note that a request using the GET or HEAD method cannot have a body.


cacheOptional ​
cache: RequestCache;

The cache mode you want to use for the request.


headersOptional ​
headers: MutMap<str>;
  • Type: MutMap<str>

Any headers you want to add to your request.


methodOptional ​
method: HttpMethod;

The request method, e.g., GET, POST. The default is GET.


redirectOptional ​
redirect: RequestRedirect;

An enum specifying the redirect mode to use: follow, error or manual.

The default is follow.


referrerOptional ​
referrer: str;
  • Type: str
  • Default: about:client

A string specifying "no-referrer", client, or a URL.

The default is "about:client".


timeoutOptional ​
timeout: duration;

Timeout for terminating a pending request.

None if undefined.


Response ​

The response to a HTTP request.

Initializer ​

bring http;

let Response = http.Response{ ... };

Properties ​

NameTypeDescription
body
strA string representation of the body contents.
headers
MutMap<str>The map of header information associated with the response.
ok
boolA boolean indicating whether the response was successful (status in the range 200 – 299) or not.
status
numThe status code of the response.
url
strThe URL of the response.

bodyRequired ​
body: str;
  • Type: str

A string representation of the body contents.


headersRequired ​
headers: MutMap<str>;
  • Type: MutMap<str>

The map of header information associated with the response.


okRequired ​
ok: bool;
  • Type: bool

A boolean indicating whether the response was successful (status in the range 200 – 299) or not.


statusRequired ​
status: num;
  • Type: num

The status code of the response.

(This will be 200 for a success).


urlRequired ​
url: str;
  • Type: str

The URL of the response.


Url ​

An URL following WHATWG URL Standard.

Initializer ​

bring http;

let Url = http.Url{ ... };

Properties ​

NameTypeDescription
hash
strThe URL's fragment.
host
strThe URL's host.
hostname
strThe URL's hostname.
href
strThe entire URL.
origin
strThe URL's origin.
password
strThe URL’s password.
pathname
strThe URL's pathname.
port
strThe URL's port.
protocol
strThe URL's protocol.
search
strThe URL's search.
username
strThe URL's username.

hashRequired ​
hash: str;
  • Type: str

The URL's fragment.


hostRequired ​
host: str;
  • Type: str

The URL's host.


hostnameRequired ​
hostname: str;
  • Type: str

The URL's hostname.


hrefRequired ​
href: str;
  • Type: str

The entire URL.


originRequired ​
origin: str;
  • Type: str

The URL's origin.


passwordRequired ​
password: str;
  • Type: str

The URL’s password.


pathnameRequired ​
pathname: str;
  • Type: str

The URL's pathname.


portRequired ​
port: str;
  • Type: str

The URL's port.


protocolRequired ​
protocol: str;
  • Type: str

The URL's protocol.


searchRequired ​
search: str;
  • Type: str

The URL's search.


usernameRequired ​
username: str;
  • Type: str

The URL's username.


Enums ​

HttpMethod ​

The request's method.

Members ​

NameDescription
GET
GET.
PUT
PUT.
DELETE
DELETE.
PATCH
PATCH.
POST
POST.
OPTIONS
OPTIONS.
HEAD
HEAD.
CONNECT
CONNECT.
TRACE
TRACE.

GET ​

GET.


PUT ​

PUT.


DELETE ​

DELETE.


PATCH ​

PATCH.


POST ​

POST.


OPTIONS ​

OPTIONS.


HEAD ​

HEAD.


CONNECT ​

CONNECT.


TRACE ​

TRACE.


RequestCache ​

The cache mode of the request.

It controls how a request will interact with the system's HTTP cache.

Members ​

NameDescription
DEFAULT
The runtime environment looks for a matching request in its HTTP cache.
NO_STORE
The runtime environment fetches the resource from the remote server without first looking in the cache, and will not update the cache with the downloaded resource.
RELOAD
The runtime environment fetches the resource from the remote server without first looking in the cache, but then will update the cache with the downloaded resource.
NO_CACHE
The runtime environment looks for a matching request in its HTTP cache.
FORCE_CACHE
The runtime environment looks for a matching request in its HTTP cache.

DEFAULT ​

The runtime environment looks for a matching request in its HTTP cache.

  • If there is a match and it is fresh, it will be returned from the cache.
  • If there is a match but it is stale, the runtime environment will make a conditional request to the remote server.
  • If the server indicates that the resource has not changed, it will be returned from the cache.
  • Otherwise the resource will be downloaded from the server and the cache will be updated.
  • If there is no match, the runtime environment will make a normal request, and will update the cache with the downloaded resource.

NO_STORE ​

The runtime environment fetches the resource from the remote server without first looking in the cache, and will not update the cache with the downloaded resource.


RELOAD ​

The runtime environment fetches the resource from the remote server without first looking in the cache, but then will update the cache with the downloaded resource.


NO_CACHE ​

The runtime environment looks for a matching request in its HTTP cache.

  • If there is a match, fresh or stale, the runtime environment will make a conditional request to the remote server.
  • If the server indicates that the resource has not changed, it will be returned from the cache. Otherwise the resource will be downloaded from the server and the cache will be updated.
  • If there is no match, the runtime environment will make a normal request, and will update the cache with the downloaded resource.

FORCE_CACHE ​

The runtime environment looks for a matching request in its HTTP cache.

  • If there is a match, fresh or stale, it will be returned from the cache.
  • If there is no match, the runtime environment will make a normal request, and will update the cache with the downloaded resource.

RequestRedirect ​

The redirect read-only property that contains the mode for how redirects are handled.

Members ​

NameDescription
MANUAL
Do not follow redirects automatically.
FOLLOW
Follow all redirects incurred when fetching a resource.
ERROR
Return a network error when a request is met with a redirect.

MANUAL ​

Do not follow redirects automatically.

The Location response header includes the redirect target.


FOLLOW ​

Follow all redirects incurred when fetching a resource.


ERROR ​

Return a network error when a request is met with a redirect.