Last active
October 1, 2015 18:26
-
-
Save Deraen/7abc08fe085526d204c0 to your computer and use it in GitHub Desktop.
JSON key-fn with compojure-api and ring-middleware-format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns examples.thingie | |
(:require [ring.util.http-response :refer :all] | |
[compojure.api.sweet :refer :all] | |
[camel-snake-kebab.core :refer :all])) | |
;; Requires compojure-api 0.24.0-SNAPSHOT and ring-middleware-format 0.7.0-SNAPSHOT | |
;; | |
;; Routes | |
;; | |
(defn key-json->clj [x] | |
(keyword (->kebab-case x))) | |
(defn key-clj->json [x] | |
(->camelCase (if (keyword? x) (name x) x))) | |
(defapi app | |
{:format {:formats [:json] | |
:params-opts {:json {:key-fn key-json->clj}} | |
:response-opts {:json {:key-fn key-clj->json}}}} | |
(swagger-ui) | |
(swagger-docs | |
{:info {:version "1.0.0" | |
:title "Thingies API"}}) | |
(GET* "/foo" [] | |
(ok {:test-foo 5 | |
:asd-asd "Foo"})) | |
(POST* "/foo" [] | |
:body [body {:test-foo Long | |
:asd-ads String}] | |
(println body) | |
(ok body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@benearlam I didn't get around to finalizing ring-middleware-format changes 5 months ago.
Now in latest snapshot ring-middleware-format (ngrunwald repo, not metosin fork) should support this. Latest compojure-api depends on that.