Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Sample JSON echo service in clojure.
Browse files Browse the repository at this point in the history
  • Loading branch information
aeden committed May 7, 2012
0 parents commit 7fbb4ef
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions echo/clojure/echo/.gitignore
@@ -0,0 +1,6 @@
pom.xml
*jar
/lib/
/classes/
.lein-failures
.lein-deps-sum
27 changes: 27 additions & 0 deletions echo/clojure/echo/README
@@ -0,0 +1,27 @@
# echo

Web service written in clojure that parses and echoes JSON data.

## Usage

Install leiningen:

brew install leiningen

Download required dependencies:

lein deps

Run the service:

lein exec bin/server.clj

Call the service from curl:

curl -i "http://127.0.0.1:3000" -d '{"foo":"bar"}'

## License

Copyright (C) 2012 Anthony Eden

Distributed under the MIT License.
3 changes: 3 additions & 0 deletions echo/clojure/echo/bin/server.clj
@@ -0,0 +1,3 @@
(use 'ring.adapter.jetty)
(use 'echo.core)
(run-jetty app {:port 3000})
7 changes: 7 additions & 0 deletions echo/clojure/echo/project.clj
@@ -0,0 +1,7 @@
(defproject echo "1.0.0-SNAPSHOT"
:description "Web service that parses and echoes JSON data"
:dependencies [[org.clojure/clojure "1.3.0"]
[ring/ring "1.1.0"]
[cheshire "4.0.0"]]
:dev-dependencies [[lein-exec "0.1"]
[ring-mock "0.1.2"]])
7 changes: 7 additions & 0 deletions echo/clojure/echo/src/echo/core.clj
@@ -0,0 +1,7 @@
(ns echo.core
(:use [cheshire.core]))

(defn app [request]
{:status 200
:headers {"Content-Type" "application/json"}
:body (generate-string (parse-string (slurp (request :body))))})
10 changes: 10 additions & 0 deletions echo/clojure/echo/test/echo/test/core.clj
@@ -0,0 +1,10 @@
(ns echo.test.core
(:use [echo.core])
(:use [clojure.test])
(:use [ring.mock.request]))

(deftest app-test
(is (= (app (body (request :post "/"), "{\"foo\":\"bar\"}"))
{:status 200
:headers {"Content-Type" "application/json"}
:body "{\"foo\":\"bar\"}"})))

0 comments on commit 7fbb4ef

Please sign in to comment.