Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Last active December 12, 2016 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayato-p/91a0c4d8008793e4d3f2 to your computer and use it in GitHub Desktop.
Save ayato-p/91a0c4d8008793e4d3f2 to your computer and use it in GitHub Desktop.
`lein new demo` で作って下のコードを貼り付けるだけ。
(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}))
(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