Skip to content

Commit 1057968

Browse files
committed
feat: support all endpoints
1 parent 96ccbb1 commit 1057968

File tree

2 files changed

+64
-20
lines changed

2 files changed

+64
-20
lines changed

bin/test_eio.ml

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ let () =
1111
let req : Api.Request.eval_req_src =
1212
{ src = "let f x = x + 1"; syntax = Iml }
1313
in
14-
let result = Main_eio.eval config req http ~sw in
14+
let _ = Main_eio.eval config req ~sw ~client:http in
15+
let result =
16+
Main_eio.instance_by_src config ~client:http ~sw
17+
{
18+
src = "fun (x : int) -> f x > 4";
19+
syntax = Iml;
20+
hints = None;
21+
instance_printer = Some { name = "Z.sprint ()"; cx_var_name = "x" };
22+
}
23+
in
1524
match result with
1625
| Ok st ->
1726
Log.app (fun k ->
@@ -23,9 +32,12 @@ let () =
2332
| `Error_decoding_response err ->
2433
Log.err (fun k ->
2534
k "Decoding error: %a@." Decoders_yojson.Basic.Decode.pp_error err)
26-
| `Error_response (code, _err) ->
35+
| `Error_response (code, err) ->
2736
Log.err (fun k ->
28-
k "Error response: Code = %s" (Cohttp.Code.string_of_status code)))
37+
k "Error response: Code = %s @. %a"
38+
(Cohttp.Code.string_of_status code)
39+
CCFormat.(some Api.Response.pp_capture)
40+
err.capture))
2941
in
3042

3143
Eio_main.run @@ fun env ->

src/main_eio.ml

+49-17
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,71 @@ let read (dec : 'a Decoders_yojson.Basic.Decode.decoder)
5858
read_error body
5959
|> CCResult.flat_map (fun err -> Error (`Error_response (status, err)))
6060

61-
(* let net =
62-
let open Eio.Std in
63-
let net = Eio_mock.Net.make "mocknet" in
64-
Eio_mock.Net.on_getaddrinfo net
65-
[ `Return [ `Tcp (Eio.Net.Ipaddr.V4.loopback, 443) ] ];
66-
let conn = Eio_mock.Flow.make "connection" in
67-
Eio_mock.Net.on_connect net [ `Return conn ];
68-
net *)
69-
70-
let eval (c : Config.t) (req : Api.Request.eval_req_src) ~sw cl =
61+
let eval (c : Config.t) (req : Api.Request.eval_req_src) ~sw ~client =
7162
let uri = build_uri c "/eval/by-src" in
7263
let headers = default_headers c |> Cohttp.Header.of_list in
7364
let body = make_body E.Request.eval_req_src req in
74-
let res = Cohttp_eio.Client.call cl ~sw `POST uri ~headers ~body in
65+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
7566
read D.Response.eval_result res
7667

77-
let get_history (c : Config.t) cl ~sw =
68+
let get_history (c : Config.t) ~client ~sw =
7869
let uri = build_uri c "/history" in
7970
let headers = default_headers c |> Cohttp.Header.of_list in
80-
let resp, body = Cohttp_eio.Client.get cl ~sw uri ~headers in
71+
let resp, body = Cohttp_eio.Client.get client ~sw uri ~headers in
8172

8273
Logs.debug (fun k -> k "%s" (body |> Eio.Flow.read_all));
8374
read Decoders_yojson.Basic.Decode.string (resp, body)
8475

85-
let get_status (c : Config.t) cl ~sw =
76+
let get_status (c : Config.t) ~client ~sw =
8677
let uri = build_uri c "/status" in
8778
let headers = default_headers c |> Cohttp.Header.of_list in
88-
let resp, body = Cohttp_eio.Client.get cl ~sw uri ~headers in
79+
let resp, body = Cohttp_eio.Client.get client ~sw uri ~headers in
8980
(* Logs.debug (fun k -> k "%s" (body |> Eio.Flow.read_all)); *)
9081
read Decoders_yojson.Basic.Decode.string (resp, body)
9182

92-
let reset (c : Config.t) cl ~sw =
83+
let instance_by_name (c : Config.t) req ~client ~sw =
84+
let uri = build_uri c "/instance/by-name" in
85+
let headers = default_headers c |> Cohttp.Header.of_list in
86+
let body = make_body E.Request.instance_req_name req in
87+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
88+
read D.Response.instance_result res
89+
90+
let instance_by_src (c : Config.t) req ~client ~sw =
91+
let uri = build_uri c "/instance/by-src" in
92+
let headers = default_headers c |> Cohttp.Header.of_list in
93+
let body = make_body E.Request.instance_req_src req in
94+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
95+
read D.Response.instance_result res
96+
97+
let reset (c : Config.t) ~client ~sw =
9398
let uri = build_uri c "/reset" in
9499
let headers = default_headers c |> Cohttp.Header.of_list in
95-
let res = Cohttp_eio.Client.call cl ~sw `POST uri ~headers in
100+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers in
96101
read D.Response.reset_result res
102+
103+
let shutdown (c : Config.t) ~client ~sw =
104+
let uri = build_uri c "/shutdown" in
105+
let headers = default_headers c |> Cohttp.Header.of_list in
106+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers in
107+
read Decoders_yojson.Basic.Decode.string res
108+
109+
let verify_by_name (c : Config.t) req ~client ~sw =
110+
let uri = build_uri c "/verify/by-name" in
111+
let headers = default_headers c |> Cohttp.Header.of_list in
112+
let body = make_body E.Request.verify_req_name req in
113+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
114+
read D.Response.verify_result res
115+
116+
let verify_by_src (c : Config.t) req ~client ~sw =
117+
let uri = build_uri c "/verify/by-src" in
118+
let headers = default_headers c |> Cohttp.Header.of_list in
119+
let body = make_body E.Request.verify_req_src req in
120+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
121+
read D.Response.verify_result res
122+
123+
let decompose (c : Config.t) req ~client ~sw =
124+
let uri = build_uri c "/decompose" in
125+
let headers = default_headers c |> Cohttp.Header.of_list in
126+
let body = make_body E.Request.decomp_req_src req in
127+
let res = Cohttp_eio.Client.call client ~sw `POST uri ~headers ~body in
128+
read D.Response.decompose_result res

0 commit comments

Comments
 (0)