Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
(ns httpjson.core
(:require [clj-http.client :as client]))
(defn create-db
(client/request {:as :json
:accept :json
:content-type :json
:method :put
:url (str "" db)
:throw-exceptions false}))
(defn -main
[& args]
(prn (create-db "mydb"))
(prn (create-db "mydb")))
# First attempt, decodes body to a map
{:trace-redirects [""], :request-time 175, :status 201, :headers {"server" "CouchDB/1.2.0 (Erlang OTP/R15B01)", "location" "", "date" "Wed, 06 Mar 2013 17:13:12 GMT", "content-type" "application/json", "content-length" "12", "cache-control" "must-revalidate"}, :body {:ok true}}
# Second attempt, normally throws an exception. With :throw-exceptions false, body is a string.
{:trace-redirects [""], :request-time 5, :status 412, :headers {"server" "CouchDB/1.2.0 (Erlang OTP/R15B01)", "date" "Wed, 06 Mar 2013 17:13:12 GMT", "content-type" "application/json", "content-length" "95", "cache-control" "must-revalidate"}, :body "{\"error\":\"file_exists\",\"reason\":\"The database could not be created, the file already exists.\"}\n"}
(defproject httpjson "0.0.0"
:main httpjson.core
:dependencies [[org.clojure/clojure "1.4.0"]
[clj-http "0.6.4"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.