Last active
July 19, 2016 19:56
-
-
Save iamdustan/162678a509b32f8e2875072fa4e14453 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
/* Converting https://github.com/rgrinberg/opium#hello-world to Reason */ | |
open Opium.Std; | |
type person = { | |
name: string, | |
age: int, | |
}; | |
let json_of_person {name, age} => Ezjsonm.(dict [("name", string name), ("age", int age)]); | |
/* Original Ocaml | |
let json_of_person { name ; age } = | |
let open Ezjsonm in | |
dict [ "name", (string name) | |
; "age", (int age) ] | |
*/ | |
let print_param = put "/hello/:name" (fun req => `String ("Hello " ^ param req "name") |> respond'); | |
let print_hello = get "/" (fun req => `String ("Hello World") |> respond'); | |
let print_person = get "/person/:name/:age" ( | |
fun req => { | |
let person = { | |
name: param req "name", | |
age: "age" |> param req |> int_of_string | |
}; | |
`Json (person |> json_of_person) |> respond' | |
} | |
); | |
/* |> get "/" (fun req -> `String ("Hello World") |> respond') */ | |
App.empty | |
|> print_hello | |
|> print_param | |
|> print_person | |
|> App.run_command; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment