package resto-cohttp-server

  1. Overview
  2. Docs

Parameters

module Encoding : Resto.ENCODING
module Log : LOGGING

Signature

module Media_type : module type of struct include Resto_cohttp.Media_type.Make(Encoding) end
module Directory : module type of struct include Resto_directory.Make(Encoding) end
type server

A handle on the server worker.

A callback passed to Cohttp_lwt_unix.Server.make_response_action. Callbacks are exposed in order to give users a way to modify the arguments of the callback used to launch the server, or add some behaviour.

val init_server : ?cors:Resto_cohttp.Cors.t -> ?agent:string -> ?acl:Resto_acl.Acl.t -> media_types:Media_type.t list -> unit Directory.t -> server

Initializes the server

val resto_callback : server -> callback

resto_callback server is the default callback for resto. It can be used as is so the server simply handles requests. For example:

let server = Server.init_server ~media_types directory in
let callback = Server.resto_callback server in
Server.launch server ~callback (`TCP (`Port port))

Which, as resto_callback is the default, is equivalent to:

let server = Server.init_server ~media_types directory in
Server.launch server (`TCP (`Port port))

Optionally, it can be transformed in order to provide additional functionalities. For example:

let server = Server.init_server ~media_types directory in
let callback = Server.resto_callback server in
let auth_callback conn req bod =
  if check_auth req bod then
    callback con req bod
  else Lwt.return @@ `Response ... (* some form of response with 401 or 403 *)
in
Server.launch server ~callback:auth_callback (`TCP (`Port port)) >>= fun () ->
...
val launch : ?host:string -> server -> ?callback:callback -> Conduit_lwt_unix.server -> unit Lwt.t

launch server callback listening_protocol starts the given resto server initiating the listening loop using the listening_protocol. Each query will be treated using the given callback http handler.

val init_and_launch : ?host:string -> ?cors:Resto_cohttp.Cors.t -> ?agent:string -> ?acl:Resto_acl.Acl.t -> media_types:Media_type.t list -> unit Directory.t -> Conduit_lwt_unix.server -> unit Lwt.t

Initializes the server using the given arguments and starts it using resto_callback http handler. This is a condensed form of init_server, resto_callback, and launch.

val set_acl : server -> Resto_acl.Acl.t -> unit

configure the access list for this server

val shutdown : server -> unit Lwt.t

Kill an RPC server.

OCaml

Innovation. Community. Security.