This repository has been archived by the owner on May 10, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample JSON echo service in clojure.
- Loading branch information
0 parents
commit 7fbb4ef
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pom.xml | ||
*jar | ||
/lib/ | ||
/classes/ | ||
.lein-failures | ||
.lein-deps-sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(use 'ring.adapter.jetty) | ||
(use 'echo.core) | ||
(run-jetty app {:port 3000}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))))}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\"}"}))) |