package dispatch-js

All checked builds pass
  1. Overview
  2. Docs
Path-based dispatch: js_of_ocaml-specific support

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.5.0.tar.gz
sha256=021a95f89c503d546d90a7f212b369b117e45eedd91f32b5e5fcd33eea23d243
md5=2c4a28aeb35038a3c928e0ff17d97a7c

Description

ocaml-dispatch provides a basic mechanism for dispatching a request to a handler based on hierarchical path names conventionally found in URIs. It can be used both for dispatching requests in a server, as well as handing changes to hierarchical fragments in a client-side application.

This library provides a JavaScript interface for dispatching events based on DOM events.

Added to opam-repository:

README

ocaml-dispatch

ocaml-dispatch provides a basic mechanism for dispatching a request to a handler based on hierarchical path names conventionally found in URIs. It can be used both for dispatching requests in a server, as well as handing changes to hierarchical fragments in a client-side application.

Build Status

Installation

Install the library and its depenencies via OPAM:

opam install dispatch

Development

To install development versions of the library, pin the package from the root of the repository:

opam pin add .

You can install the latest changes by commiting them to the local git repository and running:

opam upgrade dispatch

For building and running the tests during development, you will need to install the oUnit package and reconfigure the build process to enable tests:

opam install oUnit
dune runtest

Usage

Dispatch is designed to work with whatever sort of handler you care to use, whether it's synchronous, Lwt-based, or Async-based. Here's a simple example of using the Dispatch.DSL module to setup routing for a "Hello, World!" server. The example assumes a Server module and request type, and that handlers should return strings that will be interpreted as the body of the response.

open Dispatch

let hello_handler keys rest request =
  let who = try List.assoc "who" keys with Not_found -> "World" in
  Printf.sprintf "Hello, %s!" who
;;

let handler request =
  let table = [
      "/"           , hello_handler
    ; "/hello/:who/", hello_handler
  ] in
  match DSL.dispatch table request.path with
  | Some handler -> handler request
  | None         -> "Not found!"
;;

let _ =
  Server.start handler

License

BSD3, see LICENSE file for its text.

Dependencies (4)

  1. js_of_ocaml-lwt >= "3.5.0"
  2. dispatch >= "0.4.0"
  3. dune >= "1.0"
  4. ocaml >= "4.03.0"

Dev Dependencies

None

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building dispatch-js with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.5.0 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure