Fork me on GitHub

We have a re-frame app that talks to a Rails based JSON API. We'd like to convert the JSON keys from snake_case to kebab-case on the re-frame end for API requests and responses. Can anyone advise on how best to tackle this? I'm wondered whether a re-frame interceptor would be best for this or perhaps a cljs-ajax interceptor?


Not an interceptor but a custom effect that does this. If you're using the http-xhrio effect, you can create custom body readers and writers that would do the conversion, and then in your custom effect you can just wrap the http-xhrio one while overriding the default body readers/writers with yours when needed.


I've dealt with a similar problem. I essentially did what p-himik describes. For the conversion, I used this camel-snake-kebab library: It's an extra dependency, so a simple mechanical transformation might be preferred if the data you are working with is pretty simple.


Thanks @U2FRKM4TW, @UDVJE9RE3! Is there an example of a custom body reader/writer anywhere?


Oh, actually another answer is interceptors, just not re-frame's ones but cljs-ajax's ones: Regarding readers/writers - cljs-ajax calls them response/request formats: The best examples are probably in the cljs-ajax source code itself.


Wonderful, thanks! I'll dive in

👍 1

Thanks, both, for your help. I ended up writing custom response/request formats for cljs-ajax as it appears it doesn't allow you to alter the content of a response body using interceptors 👍

👍 1