View Source HTTPSpec.Request (http_spec v3.0.0)
A struct for describing HTTP requests.
Summary
Types
@type body() :: iodata() | nil
@type fragment() :: String.t() | nil
@type host() :: String.t()
@type path() :: String.t()
@type query() :: String.t() | nil
@type scheme() :: :http | :https
@type t() :: %HTTPSpec.Request{ body: body(), fragment: fragment(), headers: HTTPSpec.Header.headers(), host: host(), method: method(), path: path(), port: :inet.port_number(), query: query(), scheme: scheme(), trailers: HTTPSpec.Trailer.trailers() }
@type url() :: String.t()
Functions
Builds a method.
Examples
iex> request = HTTPSpec.Request.new!([method: :post, ...])
iex> HTTPSpec.Request.build_method(request)
"POST"
iex> request = HTTPSpec.Request.new!(method: "POST", ...)
iex> HTTPSpec.Request.build_method(request)
"POST"
Builds an URL.
Examples
iex> request = HTTPSpec.Request.new!(
...> method: :get
...> scheme: :https,
...> host: "www.example.com",
...> port: 443,
...> path: "/image.png",
...> query: "size=lg",
...> fragment: "124,28"
...> )
iex> HTTPSpec.Request.build_url(request)
"https://www.example.com/image.png?size=lg#124,28"
@spec new(keyword() | map()) :: {:ok, t()} | {:error, HTTPSpec.ArgumentError.t()}
Creates a request from given options.
The options can be provided as a keyword list or a map.
Examples
HTTPSpec.Request.new(%{
method: :post,
scheme: :https,
host: "www.example.com",
port: 443,
path: "/talk",
headers: [
{"content-type", "application/x-www-form-urlencoded"},
{"accept", "text/html"}
],
body: "say=Hi&to=Mom",
query: "tone=cute"
})
And, an url
option is provided for setting scheme
, host
, port
, path
and query
in a quick way.
HTTPSpec.Request.new(%{
method: :post,
url: "https://www.example.com/talk?tone=cute",
headers: [
{"content-type", "application/x-www-form-urlencoded"},
{"accept", "text/html"}
],
body: "say=Hi&to=Mom"
})
Bang version of new/1
.
Puts body into request.
Puts query into request.