-
Notifications
You must be signed in to change notification settings - Fork 147
2.0.0 Content Negotiation (with Muuntaja)
Tommi Reiman edited this page Oct 12, 2017
·
6 revisions
- Compojure-api 2.0.0 supports JSON, EDN and Transit out-of-the-box. YAML and MessagePack are optional.
- 2.0.0 will use Muuntaja instead of ring-middleware-format for content negotiation as it's up to 10x faster.
- Muuntaja configuration guide: https://github.com/metosin/muuntaja/wiki/Configuration
(require '[compojure.api.sweet :refer :all])
(require '[ring.util.http-response :refer [ok]])
(require '[metosin.transit.dates :as transit-dates]) ;; https://github.com/metosin/metosin-common
(require '[muuntaja.core :as m])
(def muuntaja
(m/create
(-> muuntaja/default-options
(update-in
[:formats "application/transit+json"]
merge
{:decoder-opts {:handlers transit-dates/readers}
:encoder-opts {:handlers transit-dates/writers}}))))
(api
{:formats muuntaja}
(GET "/pizza" []
(ok {:now (org.joda.time.DateTime/now)})))