CARVIEW |
technomancy / clojure-http-client
- Source
- Commits
- Network (12)
- Issues (2)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
Branches (3)
- lein
- master ✓
- resourcefully
- Tags (0)
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
An HTTP client for Clojure — Read more
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Thu Dec 10 12:14:29 -0800 2009 | Check pom into git for integration with hudson,... [technomancy] |
![]() |
README.markdown | Tue May 26 17:27:30 -0700 2009 | Fix typo in readme. [technomancy] |
![]() |
pom.xml | Thu Dec 10 12:14:29 -0800 2009 | Check pom into git for integration with hudson,... [technomancy] |
![]() |
project.clj | Sat Jan 30 15:27:40 -0800 2010 | Update Clojure/contrib/swank dependency versions. [technomancy] |
![]() |
src/ | Sat Jan 30 15:27:11 -0800 2010 | Accept */* content-types by default. [technomancy] |
![]() |
test/ | Tue May 05 16:57:16 -0700 2009 | Encode each key/value pair in body map with url... [technomancy] |
Clojure HTTP Client
by Dan Larkin and Phil Hagelberg
A work in progress.
There are two namespaces, clojure.http.client, which provides a simple "request" function, and clojure.http.resourcefully, which is targeted more towards interactions with REST-based APIs.
(ns clojure.http.example
(:use [clojure.http.client]
[clojure.contrib.json.write])
(:require [clojure.http.resourcefully :as resourcefully]))
(let [response (request "https://google.com")]
(:code response) ;; 200
(:msg response) ;; "OK"
(:body-seq response)) ;; ("<html><head><meta[...]" ...
(resourcefully/put "https://localhost:5984/my-db/doc1"
{} (json-str {:hello "world"}))
(resourcefully/with-cookies {}
(resourcefully/post "https://localhost:3000/login"
{} {"user" user "password" password})
(resourcefully/get "https://localhost:3000/my-secret-page))
The request function requires a URL and optionally accepts a method (GET by default), a map of headers, a map of cookies, and a request body. The resourcefully functions take a URL, an optional headers map, and an optional body.
Request bodies may be strings, maps, or InputStreams. Strings get sent verbatim. Maps get sent as application/x-www-form-urlencoded, and InputStreams get streamed to the server 1000 bytes at a time.
The functions in resourcefully are named after the HTTP verbs. Note that resourcefully must be required :as something since it defines a "get" function, which would interfere with core if it were fully referred. Exceptions will be raised for status codes that indicate problems, so you don't have to check return codes manually. If you use resourcefully inside a "with-cookies" block, cookies will automatically be saved in a cookies ref and sent out with each request.
TODO: Connection pooling/keep-alive? Anything else? Send a message via github or the Clojure mailing list.
Licensed under the same terms as Clojure.