Last active
December 12, 2016 10:53
-
-
Save ayato-p/91a0c4d8008793e4d3f2 to your computer and use it in GitHub Desktop.
`lein new demo` で作って下のコードを貼り付けるだけ。
This file contains hidden or 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
(ns demo.core | |
(:require [compojure.core :as c :refer [defroutes GET POST]] | |
[hiccup.core :as h] | |
[hiccup.form :as hf] | |
[ring.adapter.jetty :as server] | |
[ring.util.response :as res])) | |
(defn html-response [res] | |
(res/content-type res "text/html;charset=utf-8")) | |
(defn test-handler [req] | |
(-> [:div | |
[:h1 "this is form page"] | |
(hf/form-to | |
[:post "/"] | |
(hf/text-field :test))] | |
h/html | |
res/response | |
html-response)) | |
(defn post-test-handler [req] | |
(-> (pr-str (slurp (:body req))) | |
res/response | |
html-response)) | |
(defroutes app | |
(GET "/" _ test-handler) | |
(POST "/" _ post-test-handler)) | |
(defonce server (atom nil)) | |
(reset! server | |
(server/run-jetty #'app {:port 3000 :join? false})) |
This file contains hidden or 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
(defproject demo "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.8.0"] | |
[ring "1.4.0"] | |
[compojure "1.4.0"] | |
[hiccup "1.0.5"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment