Skip to content

Instantly share code, notes, and snippets.

@ertugrulcetin
Last active April 3, 2020 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ertugrulcetin/e942e851d81febef875090b9d540c15e to your computer and use it in GitHub Desktop.
Save ertugrulcetin/e942e851d81febef875090b9d540c15e to your computer and use it in GitHub Desktop.
clj-web-app.core - Clojure ile Örnek Web Uygulaması
(ns clj-web-app.core
(:require [patika.core :refer [resource get-routes]]
[ring.adapter.jetty :refer [run-jetty]]
[compojure.core :as c]
[compojure.route :as r]))
(resource home
:get ["/"]
:content-type :html
:handle-ok (fn [ctx] "<html>
<body>
Merhaba Clojure!
<ul>
<li><a href=\"/users\">Users</a></li>
<li><a href=\"/print-request\">Pretty Print Request</a></li>
</ul>
</body>
</html>"))
(resource users
:get ["/users"]
:content-type :json
:handle-ok (fn [ctx] [{:name "Ertuğrul" :age 28}
{:name "Çetin" :age 22}]))
(resource print-request
:get ["/print-request"]
:content-type :text
:handle-ok (fn [ctx] (with-out-str (clojure.pprint/pprint ctx))))
(c/defroutes not-found (r/not-found "404!"))
(def handler (get-routes {:resource-ns-path "clj-web-app."
:not-found-route 'clj-web-app.core/not-found}))
(defn -main
[& args]
(run-jetty handler {:port 3000}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment