Skip to content

Commit

Permalink
Update part6
Browse files Browse the repository at this point in the history
  • Loading branch information
quan-nh committed Feb 22, 2024
1 parent 81eaa0f commit b76ecdf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 15 additions & 11 deletions doc/clj-web-from-the-ground-up-6.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
api

`[metosin/muuntaja "0.6.4"]`
https://cljdoc.org/d/metosin/reitit/0.6.0/doc/ring/content-negotiation

`app.clj`
```clj
(:require [muuntaja.middleware :as mw])

(defrecord App [handler db]
component/Lifecycle
(start [this]
(assoc this :handler (-> (handler db)
(mw/wrap-format)
(wrap-defaults api-defaults))))
(stop [this]
(assoc this :handler nil)))
(:require [muuntaja.core :as m]
[reitit.ring.middleware.muuntaja :as muuntaja])

(defn db-handler [req db]
{:status 200, :body (jdbc/execute! db ["SELECT 3*5 AS result"])})

(defn app-handler [db]
(ring/ring-handler
(ring/router
[["/" ok-handler]
["/db" #(db-handler % db)]]
{:data {:muuntaja m/instance
:middleware [muuntaja/format-middleware]}})
(ring/create-default-handler)))
```

json request
Expand Down
2 changes: 0 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
[ring/ring-jetty-adapter "1.11.0"]
[ring-jetty-component "0.3.1"]
[metosin/reitit "0.6.0"]
[metosin/muuntaja "0.6.4"]
[metosin/ring-http-response "0.9.1"]
; config
[aero "1.1.6"]
; db
Expand Down

0 comments on commit b76ecdf

Please sign in to comment.