Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making HTTP requests with Clojure

Tags:

http

clojure

I've just started learning Clojure and am struggling with the API changes over the past few years. In particular, in 1.2 there was an http-agent function in contrib which allowed for really simple HTTP requests:

 (http-agent "http..." :method "POST" :body "foo=1") 

This function was removed and it seems that now you should either use clojure.java.io or a 3rd party solution like http-kit or clj-http.

I'm really surprised as java.io seems much lower-level and loses the simplicity or http-agent and making http requests seems like something that should be in the core set of libraries (I realise this is very subjective).

What's the rationale for the removal of http-agent? Did it not fit with a core philosophy of Clojure? And what are recommendations for the best library to use for basic HTTP requests?

like image 963
Alistair77 Avatar asked Aug 08 '13 10:08

Alistair77


1 Answers

I cannot make authoritative statements about the reasons why any particular part of old contrib failed to make it into the new contrib, but in general things were moved over when sufficiently many people were interested, including some able and willing to maintain the new libraries. Perhaps in this case there simply wasn't enough interest.

Additionally, it is extremely straightforward to build Clojure projects on top of multiple libraries and it is not clear that the presence of an http client library in the core set of libraries or the contrib would make things any simpler and/or easier for developers than they are now, with excellent options available in the wider ecosystem.

As for particular examples of such excellent options, I'd point you towards clj-http and http.async.client (in alphabetical order; which one is appropriate depends on whether you'd benefit from firing off your requests asynchronously).

like image 126
Michał Marczyk Avatar answered Sep 17 '22 13:09

Michał Marczyk