I've recently made public an HTTP client library, built atop the  
Apache HttpClient.

<http://github.com/rnewman/clj-apache-http/tree/master>

The motivation for building my own was to expose more flexibility than  
most 'trivial' HTTP clients; that flexibility is necessary for some  
projects on which I work. For example, per-request proxy settings are  
possible (unlike Java's built-in client), and you can set a whole host  
of other properties.

Requests can be submitted to Java URIs, strings, or dictionaries of  
URI parts (scheme, host, etc.). You can supply a dictionary of headers  
for each request (of course). Query parameters are supplied as a  
dictionary, and will be encoded and sent in either a POST body or  
added to the request URI as appropriate.

Response body transformation is extensible; e.g., to allow

  (http/get "http://example.com/foo"; :as :json)

to work -- i.e., to have the response content parsed as JSON -- just  
define

  (defmethod http/entity-as :json [entity as]
    (json/decode-from-reader (http/entity-as entity :reader)))

This extension example comes from my main use for this library, a  
client for Freebase, which is a good illustration of its use. Very  
basic API calls are as simple as

  (def *mql-version*   (new URI "http://api.freebase.com/api/version";))

  (defn mql-status []
    (:content (http/get *mql-status* :as :json)))

with more complex invocations looking something like

  (http/post *mql-write*
             :headers (assoc input-headers "X-Metaweb-Request" "x")
             :parameters input-params
             :query { ... }
             :as :json
             :cookie-store *cookie-store*)


Dependencies are in the lib/ directory, or you can supply your own.  
The README is moderately thorough, and includes examples.

The library is still under development. Comments, feedback, patches,  
or pull requests are most welcome. I'm sorry that there's no official  
statement of license up there yet; I expect it'll be BSD, but I'll  
update the project page when that's finalized.

MQL client announcement to follow later this week...

Thanks,

-R

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to