raxx v1.1.0 Raxx.SimpleServer behaviour

Server interface for simple request -> response interactions.

Modules that use Raxx.SimpleServer implement the Raxx.Server behaviour. Default implementations are provided for the streaming interface to buffer the request before a single call to handle_request/2.

Example

Echo the body of a request to the client

defmodule EchoServer do
  use Raxx.SimpleServer, maximum_body_length: 12 * 1024 * 1024

  def handle_request(%Raxx.Request{method: :POST, path: [], body: body}, _state) do
    response(:ok)
    |> set_header("content-type", "text/plain")
    |> set_body(body)
  end
end

Options

  • maximum_body_length (default 8MB) the maximum sized body that will be automatically buffered. For large requests, e.g. file uploads, consider implementing a streaming server.

Link to this section Summary

Types

State of application server.

Callbacks

Called with a complete request once all the data parts of a body are received.

Link to this section Types

Link to this type

state()

state() :: any()

State of application server.

Original value is the configuration given when starting the raxx application.

Link to this section Callbacks

Link to this callback

handle_request(arg1, state)

handle_request(Raxx.Request.t(), state()) :: Raxx.Response.t()

Called with a complete request once all the data parts of a body are received.

Passed a Raxx.Request and server configuration. Note the value of the request body will be a string.