twirp support
Closed this issue · 1 comments
c-cube commented
rough idea is to parse+typecheck the RPC declarations, and generate client and server code.
-
server code for a service would be, basically:
type headers = (string * string) list type handler = headers:headers -> string -> (string, string) result type service = (string list * handler) list
a service is a collection of path + handler for the path; The handler reads headers to know what format to expect (json or protobuf) and returns an error or a successful encoded response body. All decoding/encoding is inside the handler, but the HTTP specifics are delegated to the user
-
client code might be functorized:
module My_service_client(H : Http_client_sig.S) = struct let foo x y = H.get (encode_foo_query x y) |> decode_foo_response let bar x = H.get (encode_bar_query x) |> decode_bar_response …
so it can be instantiated with a variety of HTTP clients.
c-cube commented
Done out of tree in https://github.com/c-cube/ocaml-twirp