Skip to content

Commit

Permalink
Minimize defaults (#3)
Browse files Browse the repository at this point in the history
* Removed the config route and bumped some dependency versions.

* Version bump for the project.
  • Loading branch information
wdhowe authored Mar 22, 2024
1 parent f466eb3 commit 0fff23b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 31 deletions.
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject http-service-lein "1.0.0"
(defproject http-service-lein "1.1.0"

;;; Project Metadata
:description "Http service template with Leiningen."
Expand All @@ -7,8 +7,8 @@
:url "https://www.eclipse.org/legal/epl-2.0/"}

;;; Dependencies, Plugins
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.logging "1.2.4"]
:dependencies [[org.clojure/clojure "1.11.2"]
[org.clojure/tools.logging "1.3.0"]
[compojure "1.7.0"]
[environ "1.2.0"]
[http-kit "2.7.0"]
Expand Down
2 changes: 1 addition & 1 deletion src/http_service_lein/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

(def conf
"Load server configuration from the environment."
{:http-port (Integer. (or (:http-port environ/env) 8080))})
{:http-port (Integer. (get environ/env :http-port 8080))})

(comment (println "Config is:\n" conf))
3 changes: 1 addition & 2 deletions src/http_service_lein/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

(compojure/defroutes app-routes
"HTTP paths are defined here."
(compojure/context "/" request
(compojure/GET "/config" [] (default/config request))
(compojure/context "/" [request]
(compojure/GET "/healthy" [] (default/healthy request))
(compojure/GET "/help" [] (default/help request))
(route/not-found (format "Path not found: %s" (:uri request)))))
Expand Down
12 changes: 1 addition & 11 deletions src/http_service_lein/default.clj
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
(ns http-service-lein.default
(:gen-class)
(:require [clojure.tools.logging :as log]
[http-service-lein.config :as cfg]
[trptcolin.versioneer.core :as version]))

(def version "Project version."
(version/get-version "http-service-lein" "http-service-lein"))

(comment (println "Version is:" version))

(defn config
"Return the service config settings."
[request]
(log/debug (:request-method request) (:uri request))
{:status 200
:body cfg/conf})

(comment (config {:request-method :get :uri "/config"}))

(defn healthy
"Return an ok status."
[request]
Expand All @@ -32,7 +22,7 @@
(log/debug (:request-method request) (:uri request))
{:status 200
:headers {"Content-Type" "text/plain"}
:body (format "HTTP API (%s). Send requests to:\nGET /help -> This help dialog.\nGET /config -> Config settings.\nGET /healthy -> Application health check."
:body (format "HTTP API (%s). Send requests to:\nGET /help -> This help dialog.\nGET /healthy -> Application health check."
version)})

(comment (help {:request-method :get :uri "/help"}))
8 changes: 1 addition & 7 deletions test/http_service_lein/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
[http-service-lein.core :as core]
[ring.mock.request :as mock]))

(deftest app-route-config-test
(testing "app-route '/config'"
(let [response (core/app (mock/request :get "/config"))]
(is (= (:status response) 200))
(is (= true (string/includes? (:body response) "http-port"))))))

(deftest app-route-health-test
(deftest app-route-healthy-test
(testing "app-route '/healthy'"
(let [response (core/app (mock/request :get "/healthy"))]
(is (= (:status response) 200))
Expand Down
7 changes: 0 additions & 7 deletions test/http_service_lein/default_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
[clojure.test :refer [deftest is testing]]
[http-service-lein.default :as default]))

(deftest config-test
(testing "Config response."
(let [resp (default/config {:request-method :get
:uri "/config"})]
(is (= 200 (:status resp)))
(is (contains? (:body resp) :http-port)))))

(deftest healthy-test
(testing "Healthy response."
(let [resp (default/healthy {:request-method :get
Expand Down

0 comments on commit 0fff23b

Please sign in to comment.