KScript docs
EN

response fields and methods

HTTP responses returned by @api($url) in KScript.Net.

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.bytesbase64The bytes of the response body, held as a base64 value.
.cookiesmapThe cookies the response sets (its Set-Cookie headers), as a map of names to values: $reply.cookies.session.
.headersmapThe response headers as a map. A header sent more than once, such as Set-Cookie, is a list of its values.
.is_okboolTrue when the status is 2xx.
.reasonstringThe status text, such as OK or Not Found.
.statusnumberThe HTTP status code, such as 200 or 404.
.textstringThe body as text.
.urlstringThe address that was fetched.

From KScript.Net

These need <import package="KScript.Net" />import KScript.Net. See KScript.Net.

#response->check() → response KScript.Net

Throws a Network error unless the status is 2xx; otherwise returns the response.
Example
<let name="order" value="@api('https://api.example.com/orders/42')->check()->convert(from: json)" />
<echo>{ $order.id }</echo>
$order = @api('https://api.example.com/orders/42')->check()->convert(from: json)
echo $order.id

#response->header(name) → string KScript.Net

One response header (or null). For a header sent more than once, such as Set-Cookie, the first; .headers has them all.
Example
<let name="response" value="@api('https://example.com')" />
<echo>{ $response->header('Content-Type') }</echo>
$response = @api('https://example.com')
echo $response->header('Content-Type')

Methods from any