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"
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).
def self.get(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request
A GET request.
def self.head(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request
A HEAD request.
def self.delete(url: String | URI, headers: HTTP::Headers | Hash[String, String] = …) -> HTTP::Client::Request
A DELETE request.
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.
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.
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.
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).
Methods
def method -> String
The method: "GET", or any token.
def url -> URI
The URL: http or https, with a host.
def headers -> HTTP::Headers
The header fields (the client adds Host, the framing and a
User-Agent).
def body -> HTTP::Content
The body.
def to_h -> Hash[Symbol, Object]
The fields as a Hash, by name.
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.
def header(name: String, value: String) -> HTTP::Client::Request
A copy with the header name set to value (replacing it).
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).