Created
August 11, 2017 20:39
-
-
Save stepankuzmin/6d3d7346b8ffd475f361ab9ec199e8eb to your computer and use it in GitHub Desktop.
ReasonML Koa interop experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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