Response
Bastion.Response — response-building helpers.
All helpers accept an HttpServer.Conn and return an HttpServer.Conn with the appropriate content-type header set and the conn halted (via send_resp).
These are thin wrappers around HttpServer's built-in response functions with additional convenience helpers for common status codes.
Functions
Send 400 Bad Request with a descriptive message.
Send 201 Created with a plain-text body.
Send 403 Forbidden with the given message.
Send an HTML response.
Sets content-type to \"text/html; charset=utf-8\", writes body, halts conn.
Example:
Response.html(conn, 200, \"<h1>Hello</h1>\")Send 500 Internal Server Error with the given message.
Send 500 Internal Server Error with the default body \
Alias for internal_error_.
Send a JSON response.
Sets content-type to \"application/json\", writes body, halts conn.
The caller is responsible for serialising the body to a JSON string
(e.g. with Json.encode).
Example:
Response.json(conn, 200, Json.encode(my_map))Send 405 Method Not Allowed.
Send 204 No Content (empty body).
Send 404 Not Found with the given message.
Send 404 Not Found with the default body \
Send 200 OK with a plain-text body.
Send a raw response with an explicit status, without setting a content-type.
Useful when the content-type has already been set via put_resp_header, or
for responses with no body (e.g. 204 No Content).Send a 302 Found redirect to the given URL.
Example:
Response.redirect(conn, \"/login\")Send a 301 Moved Permanently redirect to the given URL. Use for permanent URL changes (canonicalisation, HTTPS upgrades, etc.).
Send a plain-text response.
Sets content-type to \"text/plain; charset=utf-8\", writes body, halts conn.Send 401 Unauthorized with the given message.
Send 422 Unprocessable Entity with the given message.