Skip to content

Refactor to handlers namespaceλ︎

Create a new namespace called practicalli.banking-on-clojure.handler which will contain handler functions for the routes to be defined in the application.

Additional libraries will be used to create the responses, which will only be required in the new namespace.

Create a new file called src/practicalli/banking_on_clojure/handler.clj

Move the [ring.util.response :refer [response]] require and the handler function from src/practicalli/banking_on_clojure/service.clj to src/practicalli/banking_on_clojure/handler.clj

(ns practicalli.banking-on-clojure.handler
  "Handler functions to satisfy requests to the service"
    [ring.util.response :refer [response]]))
(defn welcome-page
  "Main page layout for the service"
  (response "Banking on Clojure"))

Require the practicalli.banking-on-clojure.handler namespace in practicalli.banking-on-clojure namespace, using the alias handler

(ns practicalli.banking-on-clojure
  (:require [org.httpkit.server :as app-server]
            [compojure.core :refer [defroutes GET]]
            [ring.util.response :refer [response]]
            [practicalli.handler :as handler]))

Update the request routing code to use the new alias for handlers

(defroutes app
  (GET "/" [] handler/welcome-page))

Restart the server to pick up the changes

(app-server-restart "8888")

Check the server is still working by visiting http://localhost:8888/