data HTTP::Client::Request(method: String, url: URI, headers: HTTP::Headers, body: HTTP::Content)

A request: a value, so that a program (or a cog signing requests) can build it, change it with #header and with, and send it with Client#request.

req = HTTP::Client::Request.post("https://example.com/inbox", body: "{}",
                                 content_type: "application/json")
        .header("Date", "Sat, 07 Nov 2026 00:00:00 GMT")
req.method                    # => "POST"
req.url.host                  # => "example.com"
req.headers["content-type"]   # => "application/json"

<std:http>:2208

Class methods

def self.new(method: String, url: String | URI, *, headers: HTTP::Headers | Hash[String, String] = …, body: HTTP::Content = …) -> HTTP::Client::Request

Raises ArgumentError for a method that is not a token or a URL that is not http or https with a host (or holds whitespace or a control character).

<std:http>:2222

def self.get(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A GET request.

<std:http>:2244

def self.head(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A HEAD request.

<std:http>:2249

def self.delete(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A DELETE request.

<std:http>:2254

def self.post(url: String | URI, body: String | Bytes = …, content_type: String? = …, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A POST request with body, its Content-Type content_type when given.

<std:http>:2260

def self.put(url: String | URI, body: String | Bytes = …, content_type: String? = …, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A PUT request, as .post.

<std:http>:2266

def self.patch(url: String | URI, body: String | Bytes = …, content_type: String? = …, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request

A PATCH request, as .post.

<std:http>:2272

def self.stream(method: String, url: String | URI, headers: HTTP::Headers | Hash[String, String] = …, &write: shareable (HTTP::BodyWriter) -> Void) -> HTTP::Client::Request

A request whose body the block writes, chunk by chunk (sent chunked).

<std:http>:2279

Methods

def method -> String

The method: "GET", or any token.

<std:http>:2210

def url -> URI

The URL: http or https, with a host.

<std:http>:2212

def headers -> HTTP::Headers

The header fields (the client adds Host, the framing and a User-Agent).

<std:http>:2215

def body -> HTTP::Content

The body.

<std:http>:2217

def to_h -> Hash[Symbol, Object]

The fields as a Hash, by name.

<std:http>:2222

def with(*, method: String? = …, url: String | URI | Nil = …, headers: HTTP::Headers | Hash[String, String] | Nil = …, body: HTTP::Content? = …) -> HTTP::Client::Request

A copy with the fields given changed.

<std:http>:2294

def header(name: String, value: String) -> HTTP::Client::Request

A copy with the header name set to value (replacing it).

<std:http>:2300

def idempotent? -> Bool

Whether sending it twice does what sending it once does: GET, HEAD, PUT, DELETE, OPTIONS (a kept connection found closed is retried only then).

<std:http>:2305