-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
While running the server on port 8084: | ||
|
||
```sh | ||
$ PORT=8084 dune exec examples/twirp_ezcurl/calculator_client.exe | ||
query on http://localhost:8084/ | ||
add call: returned 131 | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
syntax = "proto3"; | ||
|
||
message DivByZero {} | ||
|
||
message I32 { | ||
int32 value = 0; | ||
} | ||
|
||
message AddReq { | ||
int32 a = 1; | ||
int32 b = 2; | ||
} | ||
|
||
message AddAllReq { | ||
repeated int32 ints = 1; | ||
} | ||
|
||
message Empty {} | ||
|
||
service Calculator { | ||
rpc add(AddReq) returns (I32); | ||
|
||
rpc add_all(AddAllReq) returns (I32); | ||
|
||
rpc ping(Empty) returns (Empty); | ||
|
||
rpc get_pings(Empty) returns (I32); | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
let spf = Printf.sprintf | ||
let aspf = Format.asprintf | ||
|
||
let () = | ||
let port = try int_of_string (Sys.getenv "PORT") with _ -> 8080 in | ||
Printf.printf "query on http://localhost:%d/\n%!" port; | ||
|
||
let r = | ||
match | ||
Twirp_ezcurl.call ~use_tls:false ~host:"localhost" ~port | ||
Calculator.Calculator.add | ||
@@ Calculator.default_add_req ~a:31l ~b:100l () | ||
with | ||
| Ok x -> x.value |> Int32.to_int | ||
| Error err -> | ||
failwith (aspf "call to add failed: %a" Twirp_ezcurl.pp_error err) | ||
in | ||
|
||
Printf.printf "add call: returned %d\n%!" r; | ||
() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
(executable | ||
(name calculator_client) | ||
(flags :standard -w -40) | ||
(libraries ezcurl twirp_ezcurl)) | ||
|
||
(rule | ||
(targets calculator.ml calculator.mli) | ||
(deps calculator.proto) | ||
(action | ||
(run ocaml-protoc --binary --pp --yojson --services --ml_out ./ %{deps}))) |