-
-
Save kaze/e242a4ef3050f5b939af873b83fadf47 to your computer and use it in GitHub Desktop.
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
(ns my-backend.core | |
(:gen-class) | |
(:require [compojure.core :as c] | |
[compojure.route :as route] | |
[ring.adapter.jetty :as jetty] | |
[ring.middleware.defaults :as ring-defaults] | |
[hiccup2.core :as h] | |
#_[muuntaja.core :as m] | |
[muuntaja.middleware :as muuntaja])) | |
(defonce server (atom nil)) | |
(defn home-view [count] | |
[:html | |
[:body | |
[:h1 "Welcome home!"] | |
[:ul | |
(for [i (range count)] | |
[:li i])]]]) | |
(defn routes [] | |
(c/routes | |
(c/GET "/" [count] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body (str (h/html (home-view (Integer. (or count 0)))))}) | |
(c/GET "/:foo" [foo] | |
{:status 200 | |
:body (str "you asked for " foo)}) | |
(c/POST "/api" [:as req] | |
(clojure.pprint/pprint (:body-params req)) | |
{:status 200 | |
:body {:hello 123}}))) | |
(defn handler [req] | |
((routes) req)) | |
(defn start-jetty! [] | |
(reset! | |
server | |
(jetty/run-jetty (-> #'handler | |
muuntaja/wrap-format | |
(ring-defaults/wrap-defaults ring-defaults/api-defaults)) | |
{:join? false | |
:port 3428}))) | |
(defn stop-jetty! [] | |
(.stop @server) | |
(reset! server nil)) | |
(defn -main [& args] | |
(start-jetty!)) | |
#_(start-jetty!) |
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
{:paths ["src"] | |
:deps {ring/ring-jetty-adapter {:mvn/version "1.9.4"} | |
ring/ring-defaults {:mvn/version "0.3.3"} | |
compojure/compojure {:mvn/version "1.6.2"} | |
hiccup/hiccup {:mvn/version "2.0.0-alpha2"} | |
metosin/muuntaja {:mvn/version "0.6.8"}}} |
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
. | |
├── deps.edn | |
├── src | |
│ └── my_backend | |
│ └── core.clj | |
└── tree | |
2 directories, 3 files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment