HTTPStream.Request (HTTPStream v1.0.0) View Source

Struct that represents a request.

Fields:

  • scheme: atom() - e.g. :http
  • host: binary() - e.g. "localhost"
  • port: integer() - e.g. 80
  • path: binary() - e.g "/users/1/avatar.png"
  • method: String.t() - e.g. "GET"
  • headers: keyword() - e.g. [authorization: "Bearer 123"]
  • body: binary() - e.g. { "id": "1" }

Link to this section Summary

Functions

Parses a given URL and uses a given method to generate a valid HTTPStream.Request struct.

Link to this section Types

Specs

t() :: %HTTPStream.Request{
  body: binary(),
  headers: keyword(),
  host: binary() | nil,
  method: binary(),
  path: binary(),
  port: integer(),
  scheme: atom() | nil
}

Link to this section Functions

Link to this function

new(method, url, opts \\ [])

View Source

Specs

new(String.t(), String.t(), keyword()) :: t() | no_return()

Parses a given URL and uses a given method to generate a valid HTTPStream.Request struct.

Supported options:

  • headers - HTTP headers to be sent.
  • body - Body of the HTTP request. This will be the request query field if the method is one of "GET", "TRACE", "HEAD", "OPTIONS" and "DELETE".

This function raises an ArgumentError if the HTTP method is unsupported or the url argument isn't a string.