Skip to content

Instantly share code, notes, and snippets.

@jlongster
Last active October 26, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlongster/7cb0b4d2b6ce4d634018886a926e9dc7 to your computer and use it in GitHub Desktop.
Save jlongster/7cb0b4d2b6ce4d634018886a926e9dc7 to your computer and use it in GitHub Desktop.
let router =
Router.create () |>
Router.post
"/"
(
fun req body =>
Cohttp_lwt_body.to_string body >>= (
fun body => {
let str =
switch (Uri.get_query_param (req |> Request.uri) "foo") {
| None => ""
| Some x => x
};
let json = Yojson.Basic.from_string str;
let synced_from = json |> Util.member "synced_from" |> Util.to_string;
let response = Yojson.Basic.to_string (
`Assoc [
("id", `String (Uuidm.to_string (Uuidm.v `V4))),
("devices", `String synced_from)
]
);
Server.respond_string status::`OK body::response ()
}
)
) |>
Router.get "/foo" (fun req body => Server.respond_string status::`OK body::"/foo" ()) |>
Router.get "/bar" (fun req body => Server.respond_string status::`OK body::"/bar" ());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment