lightspeed/framework/http
Core HTTP connection model for framework-compatible endpoint flows.
Types
Mutable-style immutable connection passed through middleware and handlers.
pub type Conn {
Conn(
request: Request,
response: Response,
halted: Bool,
route_params: List(RouteParam),
)
}
Constructors
-
Conn( request: Request, response: Response, halted: Bool, route_params: List(RouteParam), )
HTTP method labels.
pub type Method {
Get
Post
Put
Patch
Delete
Head
Options
Other(String)
}
Constructors
-
Get -
Post -
Put -
Patch -
Delete -
Head -
Options -
Other(String)
One request entering the endpoint.
pub type Request {
Request(
method: Method,
path: String,
headers: List(#(String, String)),
body: String,
session_id: String,
csrf_token: String,
origin: String,
session: List(#(String, String)),
flash: List(#(String, String)),
)
}
Constructors
-
Request( method: Method, path: String, headers: List(#(String, String)), body: String, session_id: String, csrf_token: String, origin: String, session: List(#(String, String)), flash: List(#(String, String)), )
HTTP response emitted by endpoint/controller handlers.
pub type Response {
Response(
status: Int,
headers: List(#(String, String)),
body: String,
session: List(#(String, String)),
flash: List(#(String, String)),
)
}
Constructors
-
Response( status: Int, headers: List(#(String, String)), body: String, session: List(#(String, String)), flash: List(#(String, String)), )
One path parameter captured from a route pattern.
pub type RouteParam {
RouteParam(name: String, value: String)
}
Constructors
-
RouteParam(name: String, value: String)
Values
pub fn flash(conn: Conn, key: String) -> option.Option(String)
Read flash entry from response state.
pub fn put_flash(conn: Conn, key: String, value: String) -> Conn
Update flash entry in response state.
pub fn put_header(conn: Conn, key: String, value: String) -> Conn
Set or replace one response header.
pub fn put_session(
conn: Conn,
key: String,
value: String,
) -> Conn
Update session entry in response state.
pub fn request(
method method: Method,
path path: String,
headers headers: List(#(String, String)),
body body: String,
session_id session_id: String,
csrf_token csrf_token: String,
origin origin: String,
session session: List(#(String, String)),
flash flash: List(#(String, String)),
) -> Request
Build a request.
pub fn request_header(
conn: Conn,
key: String,
) -> option.Option(String)
Request header by key.
pub fn response_flash(
response: Response,
) -> List(#(String, String))
Response flash state.
pub fn response_headers(
response: Response,
) -> List(#(String, String))
Response headers.
pub fn response_label(response: Response) -> String
Stable response label for fixture assertions.
pub fn response_session(
response: Response,
) -> List(#(String, String))
Response session state.
pub fn route_param(
conn: Conn,
key: String,
) -> option.Option(String)
Route param value by key.
pub fn send(
conn: Conn,
status: Int,
content_type: String,
body: String,
) -> Conn
Write a full response tuple.
pub fn session(conn: Conn, key: String) -> option.Option(String)
Read session entry from response state.
pub fn with_route_params(
conn: Conn,
params: List(RouteParam),
) -> Conn
Set route params on the connection.