Skip to content

Instantly share code, notes, and snippets.

@saschatimme
Created April 10, 2017 14:48
Show Gist options
  • Save saschatimme/9dc954aacf4c302113de4022c85bd424 to your computer and use it in GitHub Desktop.
Save saschatimme/9dc954aacf4c302113de4022c85bd424 to your computer and use it in GitHub Desktop.
Simple trick to avoid decoding / encoding if one use Bucklesript on client and server
type t = {
test: string,
value: int
};
external consume_client: string => t = "JSON.parse" [@@bs.val];
external prepare_server: t => string = "JSON.stringify" [@@bs.val];
let test = { test: "Hello", value: 42};
Js.log "test:";
Js.log test;
let sent = prepare_server test;
let consumed = consume_client sent;
Js.log "consumed:";
Js.log consumed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment