Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created July 10, 2010 02:37
Show Gist options
  • Save swannodette/470367 to your computer and use it in GitHub Desktop.
Save swannodette/470367 to your computer and use it in GitHub Desktop.
(ns second-post.couchdb
(:use aleph
[clojure.contrib.json :only [read-json json-str]])
(:require [com.twinql.clojure.http :as http])
(:import [org.apache.http HttpEntity]
[org.apache.http.entity StringEntity]))
(defn ^HttpEntity json->entity [json]
(StringEntity. (json-str json)))
(defn create-document [doc]
(http/post "http://localhost:5984/dummy"
:headers {"Content-Type" "application/json"}
:body (json->entity doc)))
(defn save [request]
(future
(create-document {:bar "test"})
(respond! request
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello world!"})))
(run-aleph save {:port 8080})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment