trevrpc/server

A TrevRPC server: native QUIC, and QMux over TLS on TCP for clients whose networks block UDP.

Types

pub type Config {
  Config(
    port: Int,
    cert_file: String,
    key_file: String,
    routes: List(Route),
    tcp: Bool,
    tcp_port: option.Option(Int),
    http: Bool,
    webtransport: Bool,
    webtransport_origins: List(String),
    max_frame_size: option.Option(Int),
    max_streams_per_connection: option.Option(Int),
    max_concurrent_requests: option.Option(Int),
    graceful_shutdown_timeout: option.Option(Int),
  )
}

Constructors

  • Config(
      port: Int,
      cert_file: String,
      key_file: String,
      routes: List(Route),
      tcp: Bool,
      tcp_port: option.Option(Int),
      http: Bool,
      webtransport: Bool,
      webtransport_origins: List(String),
      max_frame_size: option.Option(Int),
      max_streams_per_connection: option.Option(Int),
      max_concurrent_requests: option.Option(Int),
      graceful_shutdown_timeout: option.Option(Int),
    )

    Arguments

    port

    The UDP port, 0 for any free one.

    cert_file

    PEM files of the certificate, with its chain, and its key.

    tcp

    Whether to listen on TCP for QMux over TLS, by default on the UDP port’s number.

    http

    Whether to serve the HTTP mapping, over HTTP/3 and HTTP/2, which the Android client uses.

    webtransport

    Whether to serve browsers: WebTransport over HTTP/3, and QMux over WebSocket on the TCP listener.

    webtransport_origins

    The origins of the pages, besides the server’s own, that may open a browser session. Browsers always send an Origin; clients that send none are admitted too.

    graceful_shutdown_timeout

    Milliseconds the handlers get to finish on shutdown.

A method’s handler.

pub type Route
pub type Server

Values

pub fn bidi(
  method: schema.Method(request, response),
  handler: fn(handler.Call(request, response)) -> Result(
    Nil,
    status.Status,
  ),
) -> Route
pub fn client_streaming(
  method: schema.Method(request, response),
  handler: fn(handler.Call(request, response)) -> Result(
    response,
    status.Status,
  ),
) -> Route
pub fn config(
  port: Int,
  cert_file: String,
  key_file: String,
  routes: List(Route),
) -> Config

A server on port with these credentials and routes, every other option at its default.

pub fn port(server: Server) -> Result(Int, Nil)

The UDP port the server listens on, unless it has stopped.

pub fn server_streaming(
  method: schema.Method(request, response),
  handler: fn(request, handler.Call(request, response)) -> Result(
    Nil,
    status.Status,
  ),
) -> Route
pub fn start(config: Config) -> Result(Server, String)

Starts a server, linked to the calling process: it stops when that process exits. An error says what failed, such as credentials that cannot be read, a port in use, or two routes for one path.

pub fn stop(server: Server) -> Nil

Shuts the server down gracefully, and returns once it is down. Stopping a server that is already down does nothing.

pub fn tcp_port(server: Server) -> Result(Int, Nil)

The TCP port, unless TCP is off or the server has stopped.

pub fn unary(
  method: schema.Method(request, response),
  handler: fn(request, handler.Call(request, response)) -> Result(
    response,
    status.Status,
  ),
) -> Route
✨ Search Document