Skip to content

Commit

Permalink
http: turn url into a labeled arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rizo committed Apr 2, 2024
1 parent 0a60e2c commit 5907514
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
22 changes: 12 additions & 10 deletions src/helix/Helix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,24 @@ module Http : sig
?mode:Stdweb.Fetch.mode ->
encode:'a Encoder.t ->
decode:'b Decoder.t ->
string ->
url:string ->
'a ->
'b result option Signal.t

val get :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
decode:'a Decoder.t ->
string ->
url:string ->
unit ->
'a result option Signal.t

val put :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
encode:'a Encoder.t ->
decode:'b Decoder.t ->
string ->
url:string ->
'a ->
'b result option Signal.t

Expand All @@ -189,15 +190,15 @@ module Http : sig
?mode:Stdweb.Fetch.mode ->
encode:'a Encoder.t ->
decode:'b Decoder.t ->
string ->
url:string ->
'a ->
'b result option Signal.t

val delete :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
decode:'b Decoder.t ->
string ->
url:string ->
'a ->
'b result option Signal.t

Expand All @@ -208,23 +209,24 @@ module Http : sig
?mode:Stdweb.Fetch.mode ->
encode:('a -> Stdweb.Json.t) ->
decode:(Stdweb.Json.t -> ('b, 'err) Result.t) ->
string ->
url:string ->
'a ->
'b result option Signal.t

val get :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
decode:(Stdweb.Json.t -> ('a, 'err) Result.t) ->
string ->
url:string ->
unit ->
'a result option Signal.t

val put :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
encode:('a -> Stdweb.Json.t) ->
decode:(Stdweb.Json.t -> ('b, 'err) Result.t) ->
string ->
url:string ->
'a ->
'b result option Signal.t

Expand All @@ -233,15 +235,15 @@ module Http : sig
?mode:Stdweb.Fetch.mode ->
encode:('a -> Stdweb.Json.t) ->
decode:(Stdweb.Json.t -> ('b, 'err) Result.t) ->
string ->
url:string ->
'a ->
'b result option Signal.t

val delete :
?headers:(string * string) list ->
?mode:Stdweb.Fetch.mode ->
decode:(Stdweb.Json.t -> ('b, 'err) Result.t) ->
string ->
url:string ->
'a ->
'b result option Signal.t
end
Expand Down
18 changes: 9 additions & 9 deletions src/helix/Http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end

(* FIXME: prevent signal handler errors from being caught *)
let request ?meth ?(headers = []) ?mode ~encode:(content_type, to_body) ~decode
url request_value =
~url request_value =
let headers =
match content_type with
| Some content_type -> ("Content-Type", content_type) :: headers
Expand Down Expand Up @@ -107,17 +107,17 @@ let request ?meth ?(headers = []) ?mode ~encode:(content_type, to_body) ~decode
|> Promise.catch (fun err -> Signal.emit (Some (Error (Fetch_error err))) s);
s

let get ?headers ?mode ~decode url =
request ~meth:`Get ?headers ?mode ~encode:Encoder.ignore ~decode url ()
let get ?headers ?mode ~decode ~url () =
request ~meth:`Get ?headers ?mode ~encode:Encoder.ignore ~decode ~url ()

let put ?headers ?mode ~encode ~decode url request_value =
request ~meth:`Put ?headers ?mode ~encode ~decode url request_value
let put ?headers ?mode ~encode ~decode ~url request_value =
request ~meth:`Put ?headers ?mode ~encode ~decode ~url request_value

let post ?headers ?mode ~encode ~decode url request_value =
request ~meth:`Post ?headers ?mode ~encode ~decode url request_value
let post ?headers ?mode ~encode ~decode ~url request_value =
request ~meth:`Post ?headers ?mode ~encode ~decode ~url request_value

let delete ?headers ?mode ~decode url request_value =
request ~meth:`Delete ?headers ?mode ~encode:Encoder.ignore ~decode url
let delete ?headers ?mode ~decode ~url request_value =
request ~meth:`Delete ?headers ?mode ~encode:Encoder.ignore ~decode ~url
request_value

module Json = struct
Expand Down

0 comments on commit 5907514

Please sign in to comment.