HTTP.FetchOptions (http_fetch v0.9.1)

Options processing for HTTP.fetch/2 requests.

HTTP.fetch/2 accepts a flat init keyword list or map, mirroring the browser fetch(input, init) shape. Supported fetch-style options are:

  • method - HTTP method, defaulting to GET
  • headers - request headers as a list, map, or HTTP.Headers
  • body - request body
  • signal - HTTP.AbortController PID
  • redirect - :follow, :manual, or :error; defaults to :follow

The socket transport also accepts Elixir-specific extensions:

  • content_type - convenience Content-Type value for request bodies
  • timeout - request timeout in milliseconds
  • connect_timeout - connection timeout in milliseconds
  • ssl - TLS options passed to :ssl
  • socket_opts - socket options passed to the underlying transport
  • unix_socket - Unix Domain Socket path

Summary

Functions

Extracts body from options.

Extracts content type from options.

Extracts headers from options.

Extracts the HTTP method from options.

Creates a new FetchOptions struct from a flat map, keyword list, or existing FetchOptions struct.

Converts fetch init options to the internal socket transport option list.

Types

redirect()

@type redirect() :: :follow | :manual | :error

t()

@type t() :: %HTTP.FetchOptions{
  body: any(),
  connect_timeout: integer() | nil,
  content_type: String.t() | nil,
  headers: HTTP.Headers.t(),
  method: atom(),
  redirect: redirect(),
  signal: any() | nil,
  socket_opts: list() | nil,
  ssl: list() | nil,
  timeout: integer() | nil,
  unix_socket: String.t() | nil
}

Functions

get_body(fetch_options)

@spec get_body(t()) :: any()

Extracts body from options.

get_content_type(fetch_options)

@spec get_content_type(t()) :: String.t() | nil

Extracts content type from options.

get_headers(fetch_options)

@spec get_headers(t()) :: HTTP.Headers.t()

Extracts headers from options.

get_method(fetch_options)

@spec get_method(t()) :: atom()

Extracts the HTTP method from options.

new(options)

@spec new(map() | keyword() | t()) :: t()

Creates a new FetchOptions struct from a flat map, keyword list, or existing FetchOptions struct.

to_transport_options(options)

@spec to_transport_options(t()) :: keyword()

Converts fetch init options to the internal socket transport option list.