offstage

Types

pub type BadRequestResponse {
  BadRequestResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

The type representing Bearer authentication in the system

pub type BearerAuth {
  BearerAuth(token: String)
}

Constructors

  • BearerAuth(token: String)
pub type ConflictResponse {
  ConflictResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

pub type InternalServerErrorResponse {
  InternalServerErrorResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

The type representing a JSON response from the server

pub type JsonResponse(response) {
  JsonResponse(
    apply: fn(response) -> response.Response(wisp.Body),
    apply_when: fn(
      response,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

The response type for Mist.

pub type MistResponse =
  offstage_core.MistResponse
pub type NotFoundResponse {
  NotFoundResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

The common request type that supports both Wisp and Mist.

pub type Request =
  request.Request(offstage_core.Connection)
pub type RouteCapability(data, object) =
  offstage_core.RouteCapability(data, object)
pub type ServiceUnavailableResponse {
  ServiceUnavailableResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

pub type TimeoutResponse {
  TimeoutResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

pub type UnauthorizedResponse {
  UnauthorizedResponse(
    apply: fn(String) -> response.Response(wisp.Body),
    apply_when: fn(
      String,
      Bool,
      fn() -> response.Response(wisp.Body),
    ) -> response.Response(wisp.Body),
  )
}

Constructors

The response type for Wisp.

pub type WispResponse =
  response.Response(wisp.Body)

Values

pub fn bearer_auth(
  spec: offstage_core.RouteSpecBuilder,
  name: String,
  next: fn(
    offstage_core.RouteSpecBuilder,
    offstage_core.RouteCapability(BearerAuth, object),
  ) -> offstage_core.RouteSpec,
) -> offstage_core.RouteSpec

Add bearer authentication to the route.

pub fn build(
  spec: offstage_core.RouteSpecBuilder,
  builder: fn(request.Request(offstage_core.Connection)) -> Result(
    object,
    response.Response(wisp.Body),
  ),
  route: fn(request.Request(offstage_core.Connection), object) -> response.Response(
    wisp.Body,
  ),
) -> offstage_core.RouteSpec

Build a route specification from the given builder functions.

pub fn delete(route: String) -> offstage_core.RouteSpecBuilder

Create a DELETE route with the given [route] path.

pub fn description(
  spec: offstage_core.RouteSpecBuilder,
  description: String,
) -> offstage_core.RouteSpecBuilder

Set the [summary] of the route.

pub fn doc(
  spec: offstage_core.RouteSpec,
  openapi: openapi.OpenAPI,
) -> openapi.OpenAPI

Get the OpenAPI document from the given route definition

pub fn get(route: String) -> offstage_core.RouteSpecBuilder

Create a GET route with the given [route] path.

pub fn json_body(
  spec: offstage_core.RouteSpecBuilder,
  decoder: serialize.Decoder(body),
  next: fn(
    offstage_core.RouteSpecBuilder,
    offstage_core.RouteCapability(body, object),
  ) -> offstage_core.RouteSpec,
) -> offstage_core.RouteSpec

Add a json body with the given decoder to the route

pub fn json_response(
  spec: offstage_core.RouteSpecBuilder,
  code: Int,
  summary: String,
  encoder: serialize.Encoder(response),
  next: fn(
    offstage_core.RouteSpecBuilder,
    offstage_core.RouteCapability(JsonResponse(response), object),
  ) -> offstage_core.RouteSpec,
) -> offstage_core.RouteSpec
pub fn match_path_segment(
  request_segments: List(String),
  route_segments: List(String),
) -> Bool

Verify if the given request segments match the route’s segments. Parameters like ‘{id}’ will be treated as wildcards.

pub fn multipart_body(
  spec: offstage_core.RouteSpecBuilder,
  decoder: serialize.Decoder(body),
  next: fn(
    offstage_core.RouteSpecBuilder,
    offstage_core.RouteCapability(body, object),
  ) -> offstage_core.RouteSpec,
) -> offstage_core.RouteSpec

Add a multipart body with the given decoder to the route

pub fn patch(route: String) -> offstage_core.RouteSpecBuilder

Create a PATCH route with the given [route] path.

pub fn post(route: String) -> offstage_core.RouteSpecBuilder

Create a POST route with the given [route] path.

pub fn put(route: String) -> offstage_core.RouteSpecBuilder

Create a PUT route with the given [route] path.

pub fn require_authorization(
  req: request.Request(offstage_core.Connection),
  unauthorized: UnauthorizedResponse,
) -> Result(String, response.Response(wisp.Body))

Require the given token from the request headers and execute the given function accordingly

pub fn router(
  openapi: openapi.OpenAPI,
  specs: List(offstage_core.RouteSpec),
  request: request.Request(offstage_core.Connection),
) -> response.Response(wisp.Body)

Route the request to the corresponding route based on the given specs.

pub fn summary(
  spec: offstage_core.RouteSpecBuilder,
  summary: String,
) -> offstage_core.RouteSpecBuilder

Set the [summary] of the route.

pub fn tag(
  spec: offstage_core.RouteSpecBuilder,
  tag: String,
) -> offstage_core.RouteSpecBuilder

Set the [tag] of the route.

pub const try: fn(Result(a, b), fn(a) -> b) -> b

Attempt to execute the given function with the value inside the Result. This function is similar to the result.try function, returning the

✨ Search Document