Request objecttimeoutSets the maximum request execution time.
Signature: timeout(timeout: int) -> Request
Arguments: timeout is the allowed request time in seconds.
Usage Example:
$response = http.request("https://some.url", "GET")
.timeout(300)
.send();
urlDefines the URL for the HTTP request.
Signature: url(url: string) -> Request
Arguments: url is a string representing the request address.
Usage Example:
$response = http.request()
.url("http://some.url?p1=v1&p2=v2")
.method("GET")
.send();
methodDefines the HTTP method (for example, GET, POST, PUT).
Signature: method(method: string) -> Request
Arguments: method is a string with the name of the HTTP method.
Usage Example:
$response = http.request()
.url("http://some.url")
.method("POST")
.send();
bodyDefines the contents of the HTTP request body.
Signature: body(body: any) -> Request
Arguments: body is the content of the request.
Usage Example:
$response = http.request()
.url("http://some.url")
.method("PUT")
.body("example body content")
.send();
headerAdds the HTTP header to the request.
Signature: header(header: string, value: string) -> Request
Arguments:
header — the title of the title.value — the value of the header.Usage Example:
$response = http.request()
.url("http://some.url")
.method("POST")
.header("Content-Type", "application/json")
.send();
headersSets a set of HTTP headers.
Signature: headers(headers: Map) -> Request
Arguments: headers is an object where the keys are the names of the headers and the values are their values.
Usage Example:
$response = http.request()
.url("http://some.url")
.method("PUT")
.headers({"Content-Type": "application/json", "Authorization": "Bearer token"})
.send();
fileAdds a file to send in the request.
Signature:
file(FileID: string, name: string = "") -> Request
Arguments:
FileID is the identifier of the uploaded file.name is the name of the parameter for sending the file.Usage Example:
$response = http.request()
.url("http://some.url")
.method("POST")
.file($fileId, "uploaded_file")
.send();
sendSends a request and returns the response object.
Signature: send() -> Response
Usage Example:
$response = http.request()
.url("http://some.url")
.method("GET")
.send();
Response objectstatusCodeReturns the status code of the HTTP response.
Usage Example:
$code = $response.statusCode;
bodyReturns the contents of the response.
Usage Example:
$content = $response.body;
headersReturns all response headers as an object.
Usage Example:
$headers = $response.headers;
isErrorDetects if there is an error in the response. Returns true if the status code is >= 400 or there is an error field.
Usage Example:
$hasError = $response.isError();
isSuccessfulReturns true if the status code is < 400 and the error field is missing.
Usage Example:
$isSuccessful = $response.isSuccessful();
hasHeaderReturns true if the specified header is present in the response.
Signature: hasHeader(header: string) -> bool
Usage Example:
$hasContentType = $response.hasHeader("Content-Type");
headerReturns the header value with the specified name, or an empty string if there is no such header.
Signature: header(header: string) -> string
Usage Example:
$contentType = $response.header("Content-Type");
toFileSaves the response body to a file and returns its uploaded file ID.
Usage Example:
$fileId = $response.toFile();