FakeHTTP v0.1.1 FakeHTTP.Server View Source

The main interface of a scriptable HTTP server

Link to this section Summary

Functions

Returns a corresponding agent name or raises error

Returns a specification to start this module under a supervisor

Enqueue a new response which will return from the HTTP server

Resets the internal states in the server

Shutdown the server

Link to this section Types

Link to this type

headers() View Source
headers() :: [{binary(), binary()}] | %{optional(binary()) => binary()}

Link to this type

on_start() View Source
on_start() ::
  {:ok, pid()}
  | {:error, {:already_started, pid()} | {:shutdown, term()} | term()}

Link to this type

status_code() View Source
status_code() :: integer() | atom()

Link to this section Functions

Returns a corresponding agent name or raises error.

Link to this function

base_url(server) View Source
base_url(server()) :: String.t() | no_return()

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

enqueue(server, raw_response) View Source
enqueue(server(), term()) :: :ok | no_return()

Enqueue a new response which will return from the HTTP server.

Examples

Server.enqueue(server, 200)                            # 200 OK
Server.enqueue(server, :forbidden)                     # 403 Forbidden
Server.enqueue(server, %{"x" => 12345})                # application/json
Server.enqueue(server, "hello, world!")                # text/plain
Server.enqueue(server, 400, %{error: "bad_request"})   # 403 Forbidden + application/json
Link to this function

enqueue(server, status_code, body) View Source
enqueue(server(), status_code(), body()) :: :ok | no_return()

Link to this function

enqueue(server, status_code, body, headers) View Source
enqueue(server(), status_code(), body(), headers()) :: :ok | no_return()

Link to this function

reset(server) View Source
reset(server()) :: :ok

Resets the internal states in the server.

Link to this function

start_link(opts \\ []) View Source
start_link(options()) :: on_start()

Link to this function

stop(server) View Source
stop(server()) :: :ok

Shutdown the server.

Link to this function

take(server) View Source
take(server()) :: {:ok, FakeHTTP.Request.t()} | :error