[ANN] Curly - Curl CLI Wrapper

Making HTTP(s) requests in OCaml usually has the following costs:

  • Heavy dependency profile (Cohttp)
  • C bindings/Complex API (Ocurl)

Curly is an attempt to fill the gap with something that is extremely simple and only requires the curl binary to be available. It is meant for applications where the dependency profile is the most important thing. Performance, flexibility, and async support are non considerations.

Here’s an example:

Curly.(run (Request.make ~url:"https://opam.ocaml.org" ~meth:`GET ()))
3 Likes

Handy.

What do you think of also providing an even simpler interface, allowing this:

Curly.get "https://opam.ocaml.org"

These get, post, etc. functions would support the options of both Curly.Request.make and Curly.run, and the url labeled argument becomes unlabeled because it’s now the only non-optional argument.

Yeah, there’s a lot of sense in that. Will add but will stick to the most common HTTP methods. And change run to request as well.

1 Like

I think you should keep a function for building a request and a separate function for running a request. So I’d keep run as it is. You can add a function (call?) like get with an optional argument for the method, but I wouldn’t get rid of the existing run.
Building the request once and running it multiple times is useful when implementing automatic retries. So the user could implement a function like the following:

val run_with_retries : 
  ?max_attempts:int -> ?initial_delay:float -> ?multiply_delay_by:float ->
  (request -> response) -> request -> response

Note that I didn’t get rid of the existing run function, just renamed it to request (although that might not have been such a good idea).

I did a PR with what I thought you had in mind: https://github.com/rgrinberg/curly/pull/1
Or did you have something else in mind? Now I’m thinking you might just want post/get/delete/etc. to be constructors in the Request module.