Skip to content

Commit

Permalink
fix: history/status endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronsa committed Oct 10, 2024
1 parent 267a573 commit 6253e37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/imandra_http_api_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ let read (dec : 'a Decoders_yojson.Basic.Decode.decoder) (resp, body) :
in
Lwt.return res

let read_string (resp, body) : ('a, [> error ]) Lwt_result.t =
let open Lwt.Syntax in
let* body = Cohttp_lwt.Body.to_string body in
let status = Cohttp.Response.status resp in
let res =
if status = `OK then
Ok body
else
read_error body
|> CCResult.flat_map (fun err -> Error (`Error_response (status, err)))
in
Lwt.return res

let eval (c : Config.t) req =
let open Lwt.Syntax in
let uri = build_uri c "/eval/by-src" in
Expand All @@ -74,14 +87,14 @@ let get_history (c : Config.t) =
let uri = build_uri c "/history" in
let headers = default_headers c |> Cohttp.Header.of_list in
let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in
read Decoders_yojson.Basic.Decode.string res
read_string res

let get_status (c : Config.t) =
let open Lwt.Syntax in
let uri = build_uri c "/status" in
let headers = default_headers c |> Cohttp.Header.of_list in
let* res = Cohttp_lwt_unix.Client.call `GET uri ~headers in
read Decoders_yojson.Basic.Decode.string res
read_string res

let instance_by_name (c : Config.t) req =
let open Lwt.Syntax in
Expand Down
4 changes: 2 additions & 2 deletions src/imandra_http_api_client.mli
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ val eval :
(Api.Response.eval_result Api.Response.with_capture, [> error ]) result Lwt.t

val get_history :
Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t
Config.t -> (string, [> error ]) result Lwt.t

val get_status :
Config.t -> (string Api.Response.with_capture, [> error ]) result Lwt.t
Config.t -> (string, [> error ]) result Lwt.t

val instance_by_name :
Config.t ->
Expand Down

0 comments on commit 6253e37

Please sign in to comment.