Skip to content

http

Types

TypeDescription
Client An HTTP client.
Error A transport or protocol failure.
Event One item of a Server-Sent Events stream.
Response An HTTP response.
Status A response whose status is outside 200..=299.

Functions

get url … -> Response

Makes a GET request through a fresh stateless client.

head, delete, options, trace and connect do the same for their own verbs, and take the same arguments. See Client.get for the arguments and Client for what each option means.

Parameters

NameTypeDescription
url (Str | url.Url) URL to request.
:headers? Dict[Value, Value] Request headers.
:query? Dict[Value, Value] Query parameters.
:status? (:IGNORE: | "IGNORE") Pass :IGNORE: to return the response even when its status is outside 200..=299.

Example

get https://api.example.com/users do |response|
  echo $response.status

get[R] url block … -> R

Makes a GET request through a fresh stateless client and calls block with the response. The response is closed when block returns.

Parameters

NameTypeDescription
url (Str | url.Url) URL to request.
:headers? Dict[Value, Value] Request headers.
:query? Dict[Value, Value] Query parameters.
:status? (:IGNORE: | "IGNORE") Pass :IGNORE: to return the response even when its status is outside 200..=299.
block ((Response) -> R) Called with the Response.

post url … -> Response

Makes a POST request through a fresh stateless client.

put and patch do the same for their own verbs, and take the same arguments. See Client.post for the arguments and Client for what each option means.

Parameters

NameTypeDescription
url (Str | url.Url) URL to request.
:body? (Str | Bin) Request body.
:json? json.Encodable Request body, JSON-serialized.
:lines? Iterable[Value] Request body streamed with a newline after each element.
:multipart? Iterable[Dict[{name: Str, ...}]] Multipart form parts.
:headers? Dict[Value, Value] Request headers.
:query? Dict[Value, Value] Query parameters.
:status? (:IGNORE: | "IGNORE") Pass :IGNORE: to return the response even when its status is outside 200..=299.

Example

post https://api.example.com/users
  json: {name: "Alice"}

post[R] url block … -> R

Makes a POST request through a fresh stateless client and calls block with the response. The response is closed when block returns.

Parameters

NameTypeDescription
url (Str | url.Url) URL to request.
:body? (Str | Bin) Request body.
:json? json.Encodable Request body, JSON-serialized.
:lines? Iterable[Value] Request body streamed with a newline after each element.
:multipart? Iterable[Dict[{name: Str, ...}]] Multipart form parts.
:headers? Dict[Value, Value] Request headers.
:query? Dict[Value, Value] Query parameters.
:status? (:IGNORE: | "IGNORE") Pass :IGNORE: to return the response even when its status is outside 200..=299.
block ((Response) -> R) Called with the Response.