diff --git a/deps.edn b/deps.edn index 3caa086..0a35e3d 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,9 @@ {:paths ["src"] - :deps {;; http client + :deps {;api + io.pedestal/pedestal.service {:mvn/version "0.8.0-rc-1"} + io.pedestal/pedestal.http-kit {:mvn/version "0.8.0-rc-1"} + org.slf4j/slf4j-simple {:mvn/version "2.0.17"} + ;; http client clj-http/clj-http {:mvn/version "3.13.1"} ;; logging com.taoensso/telemere {:mvn/version "1.0.0"} @@ -11,27 +15,9 @@ ;; json cheshire/cheshire {:mvn/version "6.0.0"} ;; metosin/muuntaja {:mvn/version "0.6.11"} - org.clojure/clojure {:mvn/version "1.12.1"} - ;; api - ring/ring-core {:mvn/version "1.13.0"} - ring/ring-jetty-adapter {:mvn/version "1.13.0"} - org.slf4j/slf4j-simple {:mvn/version "2.0.16"} - metosin/muuntaja {:mvn/version "0.6.11"} - metosin/reitit {:mvn/version "0.9.1"}} + org.clojure/clojure {:mvn/version "1.12.1"}} :aliases {;; Run with clj -T:build function-in-build :build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}} :ns-default build}}} - -;; :aliases - ;; {:dev {:extra-deps {com.biffweb/tasks {:git/url "https://github.com/jacobobryant/biff", :git/sha "1570ccc", :git/tag "v1.8.29", :deps/root "libs/tasks"}} - ;; :extra-paths ["dev" "test"] - ;; :jvm-opts ["-XX:-OmitStackTraceInFastThrow" - ;; "-XX:+CrashOnOutOfMemoryError" - ;; "-Dbiff.env.BIFF_PROFILE=dev"] - ;; :main-opts ["-m" "com.biffweb.task-runner" "tasks/tasks"]} - ;; :prod {:jvm-opts ["-XX:-OmitStackTraceInFastThrow" - ;; "-XX:+CrashOnOutOfMemoryError" - ;; "-Dbiff.env.BIFF_PROFILE=prod"] - ;; :main-opts ["-m" "snippets"]}}} diff --git a/src/micro_blog/api.clj b/src/micro_blog/api.clj index 9a3dcdc..ae70d12 100644 --- a/src/micro_blog/api.clj +++ b/src/micro_blog/api.clj @@ -1,47 +1,19 @@ (ns micro-blog.api - (:require - [ring.adapter.jetty :as jetty] - [micro-blog.config :refer [config]] - [taoensso.telemere :as tel] - [muuntaja.middleware :as mm] - [ring.middleware.params] - [reitit.ring :as rr])) + (:require [io.pedestal.connector :as conn] + [io.pedestal.http.http-kit :as hk])) -(defn handle-ping [_args] - (tel/log! :info "Got ping request") - {:status 200, :body "ok"}) +(defn greet-handler [_request] + {:status 200 + :body "Hello, world!\n"}) -(defn handle-proc [{params :query-params}] - (let [id (get params "id")] - (tel/log! {:level :info :data {:id id}} "Got proc request") - {:status 200 - :body :ok})) +(def routes + #{["/greet" :get greet-handler :route-name :greet]}) -(defn wrap [handler id] - (fn [request] - (update (handler request) :wrap (fnil conj '()) id))) +(defn create-connector [] + (-> (conn/default-connector-map 8890) + (conn/with-default-interceptors) + (conn/with-routes routes) + (hk/create-connector nil))) -(def app - (rr/ring-handler - (rr/router - ["/api" {:middleware [ring.middleware.params/wrap-params - mm/wrap-format - [wrap :api]]} - ["/ping" {:get handle-ping}] - ["/proc" {:get handle-proc}]]) - (rr/create-default-handler))) - -(defn run-server [] - (let [port (@config :api-port) - host (@config :api-host)] - (jetty/run-jetty #'app {:port port :host host}))) - -(defn -main [] - (run-server)) - -(comment - ;; evaluate this def form to start the webapp via the REPL: - ;; :join? false runs the web server in the background! - (def server (jetty/run-jetty #'app {:port 3000 :join? false})) - ;; evaluate this form to stop the webapp via the the REPL: - (.stop server)) +(defn start [] + (conn/start! (create-connector)))