About
Build typed APIs and web applications, fast and ergonomic. Handlers are straight-line OCaml on Eio, multicore by design, and JSON is derived from your types with every input validated.
Your routes give you interactive OpenAPI docs, served by Scalar. Your types become your front end's schemas, Zod or Melange, so a changed type changes both ends.
RFC-strict, on its own HTTP/1.1 engine: every requirement it meets is a test, for HTTP, WebSockets, forms and Structured Fields. SQLite and Postgres, WebSockets, server-sent events, sessions, logging, traces and metrics are included.
HTTP and APIsData contractsData and persistenceObservabilityIdentity and access
Install
From open-opam, on OCaml 5.5 or later:
opam repo add open-opam https://github.com/open-opam/opam-repository.git
opam install spindleThen in your dune file:
(executable
(name main)
(libraries spindle eio_main)
(preprocess (pps ppx_wiretype)))In code
A route: its method and path, what it reads and what it answers, typed from the records.
open Spindle.Syntax type bill = { total : float; [@min 0.] tip : int; [@min 0] [@max 100] (** percent *) people : int; [@min 1] [@max 50] } [@@deriving wiretype] type share = { each : float } [@@deriving wiretype] let split b = let total = b.total *. float (100 + b.tip) /. 100. in Ok { each = total /. float b.people } let routes = [ Spindle.post Spindle.Path.(s "split") (Spindle.Returns.json share_json) (let+ b = Spindle.json bill_json in split b); ] let () = Spindle.Log.setup (); Eio_main.run @@ fun env -> Spindle.serve env (routes @ Spindle.Openapi.routes routes)Called. Interactive docs for every route are at /docs, generated from the same routes.
$ curl localhost:8080/split --json '{"total": 90, "tip": 10, "people": 3}' {"each":33}
Build with Hypha.
Talk to us
Bring an idea, a product or a system. Questions and feedback are just as welcome.
Services
A new product built to last, or the system your business runs on rebuilt. Hypha's expertise and its foundation, end to end.
The Factory
Make the decisions and let Hypha Autonomous Factory do the rest, turning them into a tested release, ready to ship.