less than 1 minute read

Code

In src/little_ring_things/template.clj

(ns little-ring-things.template)

(defn template [title body]
(str "<!DOCTYPE html>
<html>
<head>
    <meta charset=\"UTF-8\">
    <title>" title "</title>
</head>
<body>
    " body "
</body>
</html>"))

In src/little_ring_things/handler.clj

(ns little-ring-things.handler
(:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
            [little-ring-things.template :as t])
(:import [java.time LocalDateTime]))

(defroutes app-routes
(GET "/" []
    (t/template "Home" "<p>Hello World</p>"))

(GET "/about" []
    (t/template "About" "<p>This is Clojure ring tutorial</p>"))

(GET "/hello/:name" [name]
    (t/template "Hello" (str "<p>Hello " name "</p>")))

(GET "/time" []
    (t/template "Time" (str "<p>The current time is " (LocalDateTime/now) "</p>")))
(route/not-found "Not Found"))

(def app
(wrap-defaults app-routes site-defaults))

Notes

Updated: