atomvm_gleam/http_server
Types
Errors from http_server / TCP listen.
pub type Error {
Failed
NotSupported
Badarg
Timeout
Other(String)
}
Constructors
-
Failed -
NotSupported -
Badarg -
Timeout -
Other(String)
One router entry: path pattern + Erlang handler module atom.
Path "*" matches any URI (last-resort / catch-all), matching upstream
find_route/3. Exact path strings must match the request URI charlist.
pub type Route {
Route(path: String, module: atom.Atom)
}
Constructors
-
Route(path: String, module: atom.Atom)
Values
pub fn parse_query_string(
query: String,
) -> Result(List(#(String, String)), Error)
Parse an application/x-www-form-urlencoded query string into key/value pairs.
pub fn reply(
status_code: Int,
body: BitArray,
conn: Conn,
) -> Result(Conn, Error)
Reply with status and body, default HTML headers, then close the socket.
See http_server:reply/3.
pub fn reply_with_headers(
status_code: Int,
body: BitArray,
headers: List(BitArray),
conn: Conn,
) -> Result(Conn, Error)
Reply with status, body, and custom header lines (each including trailing \r\n).
Does not close the socket by itself (unlike reply).
See http_server:reply/4.
pub fn route(path: String, module: atom.Atom) -> Route
Build a router entry for start_server.
pub fn start_server(
port: Int,
routes: List(Route),
) -> Result(process.Pid, Error)
Listen on port and accept connections, dispatching via routes.
Returns the accept-loop pid. On listen failure upstream prints the error and
this wrapper maps a non-pid result to Failed.