Skip to content

Commit

Permalink
feat: eval
Browse files Browse the repository at this point in the history
  • Loading branch information
aidmandorky committed Feb 21, 2024
1 parent 82dbcfe commit 96ccbb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion bin/test_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ let () =

let response http ~sw =
Log.debug (fun k -> k "Sending query to server...");
let result = Main_eio.get_history config http ~sw in
let req : Api.Request.eval_req_src =
{ src = "let f x = x + 1"; syntax = Iml }
in
let result = Main_eio.eval config req http ~sw in
match result with
| Ok st ->
Log.app (fun k ->
Expand Down
18 changes: 9 additions & 9 deletions src/main_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ let read (dec : 'a Decoders_yojson.Basic.Decode.decoder)
Eio_mock.Net.on_connect net [ `Return conn ];
net *)

(* let eval (c : Config.t) (req : Api.Request.eval_req_src) ~sw cl =
let uri = build_uri c "/eval/by-src" in
let headers = default_headers c |> Cohttp.Header.of_list in
let body = make_body E.Request.eval_req_src req in
(* let res = Cohttp_eio.Client.call ~headers ~body cl `POST uri ~sw in *)
let res = Cohttp_eio.Client.get ~headers cl ~sw uri in
read D.Response.eval_result res *)
let eval (c : Config.t) (req : Api.Request.eval_req_src) ~sw cl =
let uri = build_uri c "/eval/by-src" in
let headers = default_headers c |> Cohttp.Header.of_list in
let body = make_body E.Request.eval_req_src req in
let res = Cohttp_eio.Client.call cl ~sw `POST uri ~headers ~body in
read D.Response.eval_result res

let get_history (c : Config.t) cl ~sw =
let uri = build_uri c "/history" in
let headers = default_headers c |> Cohttp.Header.of_list in
let resp, body = Cohttp_eio.Client.get cl ~sw uri ~headers in
Logs.app (fun k -> k "%s" (body |> Eio.Flow.read_all));

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

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

let reset (c : Config.t) cl ~sw =
Expand Down

0 comments on commit 96ccbb1

Please sign in to comment.