Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created August 11, 2017 20:39
Show Gist options
  • Save stepankuzmin/6d3d7346b8ffd475f361ab9ec199e8eb to your computer and use it in GitHub Desktop.
Save stepankuzmin/6d3d7346b8ffd475f361ab9ec199e8eb to your computer and use it in GitHub Desktop.
ReasonML Koa interop experiment
module Koa = {
type t;
type ctx = {. body : ref string};
/** [make ()] creates an instance of the Koa class. */
external make : unit => t = "koa" [@@bs.new] [@@bs.module];
external listen : t => int => unit = "listen" [@@bs.send];
external use : t => (ctx => unit) [@bs.uncurry] => unit = "use" [@@bs.send];
};
/** [koa ()] creates an instance of the Koa class. Alias for [Koa.make ()] */
let koa = Koa.make;
let listen app ::port=3000 () => Koa.listen app port;
let use = Koa.use;
open Koa;
let app = koa ();
let port = 3000;
let middleware ctx => ctx#body := "Hello";
use app middleware;
listen app ::port ();
Js.log @@ "Listening at http://127.0.0.1:" ^ string_of_int port;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment