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

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 clear_flash(conn: Conn) -> Conn

Clear all flash entries.

pub fn drop_session(conn: Conn, key: String) -> Conn

Delete session entry in response state.

pub fn flash(conn: Conn, key: String) -> option.Option(String)

Read flash entry from response state.

pub fn flash_all(conn: Conn) -> List(#(String, String))

Full response-flash state.

pub fn from_request(request: Request) -> Conn

Create a new connection from one request.

pub fn halt(conn: Conn) -> Conn

Halt further endpoint processing.

pub fn halted(conn: Conn) -> Bool

True when the connection has been halted.

pub fn method_label(method: Method) -> String

Stable method label.

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_body(conn: Conn) -> String

Request body.

pub fn request_csrf_token(conn: Conn) -> String

Request CSRF token.

pub fn request_header(
  conn: Conn,
  key: String,
) -> option.Option(String)

Request header by key.

pub fn request_method(conn: Conn) -> Method

Request method.

pub fn request_origin(conn: Conn) -> String

Request origin.

pub fn request_path(conn: Conn) -> String

Request path.

pub fn request_session_id(conn: Conn) -> String

Request session id.

pub fn response_body(response: Response) -> String

Response body.

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 response_status(response: Response) -> Int

Response status code.

pub fn route_param(
  conn: Conn,
  key: String,
) -> option.Option(String)

Route param value by key.

pub fn route_params(conn: Conn) -> List(RouteParam)

All route params.

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 session_all(conn: Conn) -> List(#(String, String))

Full response-session state.

pub fn set_body(conn: Conn, body: String) -> Conn

Set one response body.

pub fn set_status(conn: Conn, status: Int) -> Conn

Set one response status.

pub fn to_response(conn: Conn) -> Response

Final response.

pub fn with_route_params(
  conn: Conn,
  params: List(RouteParam),
) -> Conn

Set route params on the connection.

Search Document