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
| Name | Description |
|---|---|
| Executes a CONNECT request to a specified URL and provides a formatted response. |
| Executes a DELETE request to a specified URL and provides a formatted response. |
| Executes a HTTP request to a specified URL and provides a formatted response. |
| Serializes an URL Struct to a String. |
| Executes a GET request to a specified URL and provides a formatted response. |
| Parses the input URL String using WHATWG URL API and returns an URL Struct. |
| Executes a PATCH request to a specified URL and provides a formatted response. |
| Executes a POST request to a specified URL and provides a formatted response. |
| Executes a PUT request to a specified URL and provides a formatted response. |
| 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
- Type: RequestOptions
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
- Type: RequestOptions
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
- Type: RequestOptions
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
- Type: Url
The URL Struct to be formatted.
optionsOptional
- Type: FormatUrlOptions
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
- Type: RequestOptions
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
- Type: RequestOptions
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
- Type: RequestOptions
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
- Type: RequestOptions
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
- Type: RequestOptions
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
| Name | Type | Description |
|---|---|---|
| bool | Whether the formatted URL should include the username and password. |
| bool | Whether the formatted URL should include the fragment identifier. |
| bool | Whether the formatted URL should include the search query. |
| bool | Whether 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
| Name | Type | Description |
|---|---|---|
| str | Any body that you want to add to your request. |
| | The cache mode you want to use for the request. |
| MutMap<str> | Any headers you want to add to your request. |
| | The request method, e.g., GET, POST. The default is GET. |
| | An enum specifying the redirect mode to use: follow, error or manual. |
| str | A string specifying "no-referrer", client, or a URL. |
| | 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;
- Type: RequestCache
- Default: RequestCache.DEFAULT
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;
- Type: HttpMethod
- Default: GET
The request method, e.g., GET, POST. The default is GET.
redirectOptional
redirect: RequestRedirect;
- Type: RequestRedirect
- Default: RequestRedirect.FOLLOW
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;
- Type: duration
- Default: no timeout
Timeout for terminating a pending request.
None if undefined.
Response
The response to a HTTP request.
Initializer
bring http;
let Response = http.Response{ ... };
Properties
| Name | Type | Description |
|---|---|---|
| str | A string representation of the body contents. |
| MutMap<str> | The map of header information associated with the response. |
| bool | A boolean indicating whether the response was successful (status in the range 200 – 299) or not. |
| num | The status code of the response. |
| str | The 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
| Name | Type | Description |
|---|---|---|
| str | The URL's fragment. |
| str | The URL's host. |
| str | The URL's hostname. |
| str | The entire URL. |
| str | The URL's origin. |
| str | The URL’s password. |
| str | The URL's pathname. |
| str | The URL's port. |
| str | The URL's protocol. |
| str | The URL's search. |
| str | The 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
| Name | Description |
|---|---|
| GET. |
| PUT. |
| DELETE. |
| PATCH. |
| POST. |
| OPTIONS. |
| HEAD. |
| CONNECT. |
| 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
| Name | Description |
|---|---|
| The runtime environment looks for a matching request in its HTTP cache. |
| 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. |
| 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. |
| The runtime environment looks for a matching request in its HTTP 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
| Name | Description |
|---|---|
| Do not follow redirects automatically. |
| Follow all redirects incurred when fetching a resource. |
| 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.