/bs-protobuf

Prototype the use of ocaml-protoc with BuckleScript for Isomorphic message

Primary LanguageOCaml

bs-protobuf

Prototype the use of ocaml-protoc with BuckleScript for Isomorphic type sharing and serialization between a Javascript client and server. Note that the OCaml code is also usable with a native server.

The application consists in a server exposing a /person endpoint which returns a value of the ocaml type person. This person type was generated with the ocaml-protoc compiler. The value returned by the server is using the generated protobuf encoding as well as a Base64 encoding.

The client side of the application uses the same shared code to decode the message and pretty-print the person value.

src/shared

This directory constains all the OCaml code shared by both client and server.

First it contains OCaml libraries which are in OPAM but not in NPM. Long term solution would be to create npm packages for such libraries:

Second it contains the actual application code which consist in a single type definition (person) along with the encoding/decoding/pretty-print functions.

src/client

Client side code simply makes repetitive AJAX queries to the server for randomly generated person data. It then display the decoded value.

src/server

Server side code consists in an a simple OCaml module to generate random value of the person type. It also contain the express server.

Installation

git clone https://github.com/mransan/bs-protobuf.git bs-protobuf.git
cd bs-protobuf.git
yarn install
yarn start