Last active
April 3, 2020 11:33
-
-
Save ertugrulcetin/e942e851d81febef875090b9d540c15e to your computer and use it in GitHub Desktop.
clj-web-app.core - Clojure ile Örnek Web Uygulaması
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 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