Refactor to handlers namespace

Create a new namespace called request-handler which will contain all 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/request-handlers.clj

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

(ns practicalli.handlers
  (:require [ring.util.response :refer [response]]))
(defn welcome-page
  (response "Banking on Clojure"))

Add the practicalli.request-handler namespace to 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.request-handler :as handler]))

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

(defroutes app
  (GET "/" [] handlers/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/

results matching ""

    No results matching ""