View Source HTTPSpec.Request (http_spec v2.1.0)
A struct for describing HTTP request.
Summary
Functions
Builds a method.
Builds an URL.
Deletes the header given by name
.
Returns the values of the header specified by name
.
Creates a request from given options.
Bang version of new/1
.
Puts body into request.
Puts a request header name
to value
.
Puts a request header name
to value
unless already present.
Lazy version of put_new_header/3
.
Puts query into request.
Types
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"
Deletes the header given by name
.
All occurrences of the header are deleted, in case the header is repeated multiple times.
Examples
iex> HTTPSpec.Request.get_header(request, "cache-control")
["max-age=600", "no-transform"]
iex> request = Request.delete_header(req, "cache-control")
iex> HTTPSpec.Request.get_header(request, "cache-control")
[]
Returns the values of the header specified by name
.
Examples
iex> HTTPSpec.Request.get_header(request, "accept")
["application/json"]
iex> HTTPSpec.Request.get_header(requset, "x-unknown")
[]
@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"
})
Bang version of new/1
.
Puts body into request.
Puts a request header name
to value
.
If the header was previously set, its value is overwritten.
Examples
iex> HTTPSpec.Request.get_header(request, "accept")
[]
iex> request = Request.put_header(request, "accept", "application/json")
iex> HTTPSpec.Request.get_header(request, "accept")
["application/json"]
Puts a request header name
to value
unless already present.
See put_header/3
for more information.
Examples
iex> request =
...> request
...> |> HTTPSpec.Request.put_new_header("accept", "application/json")
...> |> HTTPSpec.Request.put_new_header("accept", "text/html")
iex> HTTPSpec.Request.get_header(request, "accept")
["application/json"]
Lazy version of put_new_header/3
.
Puts query into request.