package twirp_ezcurl

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file twirp_ezcurl.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
include Twirp_core.Client.Common

module C = Twirp_core.Client.Make (struct
  module IO = struct
    type 'a t = 'a

    let ( let* ) = ( |> )
    let return = Fun.id
  end

  type client = Ezcurl.t

  let http_post ~headers ~url ~body client () : _ result =
    match
      Ezcurl.post ~client ~url ~params:[] ~content:(`String body) ~headers ()
    with
    | Ok { code; body; headers; _ } -> Ok (body, code, headers)
    | Error (_code, str) -> Error str
end)

let call ?(client : Ezcurl.t = Ezcurl.make ()) ?encoding ?prefix ?use_tls
    ?headers ~host ~port rpc req : _ result =
  C.call ?encoding ?prefix ?use_tls ?headers ~host ~port client rpc req

exception E_twirp of error

let call_exn ?client ?encoding ?prefix ?use_tls ?headers ~host ~port rpc req =
  match
    call ?client ?encoding ?prefix ?use_tls ?headers ~host ~port rpc req
  with
  | Ok x -> x
  | Error err -> raise (E_twirp err)
OCaml

Innovation. Community. Security.