gleamrpc/http/server

Types

pub type CorsOrigins {
  AllOrigins
  CorsOrigins(origins: List(String))
}

Constructors

  • AllOrigins
  • CorsOrigins(origins: List(String))

Custom errors generated by this server

pub type HttpServerError {
  MethodUnsupported(method: http.Method)
  NoNameError
  WrongPrefix(path: String)
}

Constructors

  • MethodUnsupported(method: http.Method)
  • NoNameError
  • WrongPrefix(path: String)

Functions

pub fn cors_middleware(
  origins: CorsOrigins,
) -> fn(
  Request(Connection),
  fn(Request(Connection)) -> Response(ResponseData),
) -> Response(ResponseData)

A middleware that can be registered on a GleamRPC HTTP server to allow cross origin requests.
You can allow requests from all origins using the AllOrigins option.
Otherwise, use CorsOrigins([...]) to allow a list of allowed origins.

pub fn http_server() -> ProcedureServer(
  Request(Connection),
  Response(ResponseData),
  HttpServerError,
)

Return a GleamRPC server implementation that uses HTTP requests.
To be used with gleamrpc.with_server

pub fn init_mist(
  server: ProcedureServerInstance(
    Request(Connection),
    Response(ResponseData),
    a,
    HttpServerError,
  ),
  port: Int,
) -> Builder(Connection, ResponseData)

Using a ProcedureServerInstance, serve GleamRPC requests over HTTP with Mist
Example:

gleamrpc.with_server(http_server())
|> gleamrpc.with_context(create_context)
|> gleamrpc.with_implementation(create_user_procedure, create_user)
|> gleamrpc.with_implementation(get_user_procedure, get_user)
|> init_mist(8080)
|> mist.start_http()
Search Document