March Docs

HttpServer

HttpServer module: server-side HTTP types and pipeline runner.

Built on top of Http (for Method, Header types) and WebSocket modules. Provides the Conn type, pipeline composition, and server startup.

Usage: HttpServer.new(4000) |> HttpServer.max_connections(500) |> HttpServer.idle_timeout(30) |> HttpServer.plug(logger) |> HttpServer.plug(router) |> HttpServer.listen()

Types

typeUpgradeUpgrade = NoUpgrade | WebSocketUpgrade(WsSocket -> Unit)#
typeConnConn = Conn(#
typeServerServer = Server(#

Functions

fnassignassign(conn, key, value)#
fnassignsassigns(conn)#
fnconn_upgradeconn_upgrade(conn)#
fnfdfd(conn)#
fnget_assignget_assign(conn, key)#
fnget_req_headerget_req_header(conn, name)#
fnget_resp_headerget_resp_header(conn, name)#
fnhalthalt(conn)#
fnhaltedhalted(conn)#
fnhtmlhtml(conn, resp_status, body)#
fnidle_timeoutidle_timeout(server, secs)#
fnjsonjson(conn, resp_status, body)#
fnlistenlisten(server)#
fnmax_connectionsmax_connections(server, n)#
fnmethodmethod(conn)#

Return the request method atom (:get, :post, …) of a Conn.

fnmethod_to_stringmethod_to_string(m)#

Convert a request-method atom to its uppercase string name, suitable for logging, response bodies, or rebuilding a request line. Returns "UNKNOWN" for any atom that is not one of the recognized HTTP verbs. Atoms use lowercase by convention: :get, :post, :put, :patch, :delete, :head, :options, :trace, :connect.

Examples

    march> HttpServer.method_to_string(:get)
    "GET"
    march> HttpServer.method_to_string(:patch)
    "PATCH"
    march> HttpServer.method_to_string(:not_a_verb)
    "UNKNOWN"
fnnewnew(port)#
fnpathpath(conn)#
fnpath_infopath_info(conn)#
fnpeer_addrpeer_addr(conn)#

Return the numeric IP address of the connected peer (the socket's remote address), e.g. "203.0.113.7" or "2001:db8::1".

This is the transport-level address — it cannot be spoofed by request
headers, unlike `X-Forwarded-For`.  Behind a reverse proxy it is the
proxy's address, not the end client's.

Returns "" when no live socket backs the conn (e.g. test conns).
fnplugplug(server, p)#
fnput_resp_headerput_resp_header(conn, name, value)#
fnquery_stringquery_string(conn)#
fnredirectredirect(conn, url)#
fnreq_bodyreq_body(conn)#
fnreq_headersreq_headers(conn)#
fnresp_bodyresp_body(conn)#
fnresp_headersresp_headers(conn)#
fnrun_pipelinerun_pipeline(conn, plugs)#
fnsend_respsend_resp(conn, resp_status, body)#
fnspawn_nspawn_n(server, n)#
fnstatusstatus(conn)#
fntexttext(conn, resp_status, body)#
fnwait_forwait_for(handle)#