Created
August 13, 2018 21:21
-
-
Save kevinsimper/fcfd878e1dc945b657ee63593c87ba8e to your computer and use it in GitHub Desktop.
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
type http; | |
[@bs.deriving abstract] | |
type req = {url: string}; | |
type res; | |
[@bs.send] external _end : (res, string) => unit = "end"; | |
type handler = (req, res) => unit; | |
type server; | |
[@bs.send] external listen : (server, int) => unit = ""; | |
[@bs.send] external createServer : (http, handler) => server = ""; | |
[@bs.module] external http : http = ""; | |
let server = | |
http | |
|. createServer((req, res) => | |
switch (req |. urlGet) { | |
| "/" => res |. _end("Frontpage") | |
| "/about" => res |. _end("About") | |
} | |
); | |
server |. listen(9000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment