raxx v0.10.1 Raxx.Request

HTTP requests to a Raxx application are encapsulated in a Raxx.Request struct.

A request has all the properties of the url it was sent to. In addition it has optional content, in the body. As well as a variable number of headers that contain meta data.

Where appropriate URI properties are named from this definition.

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

from wikipedia

The contents are itemised below:

schemehttp or https, depending on the transport used.
hostThe location of the hosting server, as a binary. e.g. www.example.com.
portThe connection port on the server, as an integer.
methodThe HTTP request method, such as “GET” or “POST”, as a binary. This cannot ever be an empty string, and is always uppercase.
mountThe segments of the request URL’s “path”, that have already been matched. Same as rack path_info. This may be an empty array, if the requested URL targets the application root.
pathThe remainder of the request URL’s “path”, split into segments. It designates the virtual “location” of the request’s target within the application. This may be an empty array, if the requested URL targets the application root.
queryThe query parameters from the URL search string, formatted as a map of strings.
headersThe headers from the HTTP request as a map of strings. Note all headers will be downcased, e.g. %{"content-type" => "text/plain"}
bodyThe body content sent with the request

Examples

iex> get("http://example.com:80/some/path?query=foo", "Hello, World!", [{"content-type", "tex/plain"}])
%Raxx.Request{body: "Hello, World!",
    headers: [{"content-type", "tex/plain"}], host: "example.com",
    method: :GET, mount: [], path: ["some", "path"], port: 80,
    query: %{"query" => "foo"}, scheme: "http"}

Summary

Functions

Create a DELETE request for the given url

Create a GET request for the given url

Create a HEAD request for the given url

Create a OPTIONS request for the given url

Create a PATCH request for the given url

Create a POST request for the given url

Create a PUT request for the given url

Types

request :: %Raxx.Request{body: binary, headers: [{binary, binary}], host: binary, method: binary, mount: [binary], path: [binary], port: :inet.port_number, query: %{optional(binary) => binary}, scheme: binary}

Functions

delete(url, content \\ "", headers \\ [])

Create a DELETE request for the given url.

See get/3 for examples on adding content and headers

get(url, content \\ "", headers \\ [])

Create a GET request for the given url.

Optional content and headers can be added to the request.

Examples

iex> get("/?foo=bar").query
%{"foo" => "bar"}

iex> get({"/", %{foo: "bar"}}).query
%{"foo" => "bar"}

iex> get("/", "Hello, World!").body
"Hello, World!"

iex> get("/", [{"referer", "/home"}]).headers
[{"referer", "/home"}]
head(url, content \\ "", headers \\ [])

Create a HEAD request for the given url.

See get/3 for examples on adding content and headers

options(url, content \\ "", headers \\ [])

Create a OPTIONS request for the given url.

See get/3 for examples on adding content and headers

patch(url, content \\ "", headers \\ [])

Create a PATCH request for the given url.

See get/3 for examples on adding content and headers

post(url, content \\ "", headers \\ [])

Create a POST request for the given url.

See get/3 for examples on adding content and headers

put(url, content \\ "", headers \\ [])

Create a PUT request for the given url.

See get/3 for examples on adding content and headers