day8 / re-frame-http-fx

A re-frame "effects handler" for performing Ajax tasks (via cljs-ajax)
MIT License
259 stars 27 forks source link

Provide default response-format? #4

Open danielcompton opened 7 years ago

danielcompton commented 7 years ago

Currently, people need to provide a response format with every request, by requiring ajax.core and calling (ajax/json-response-format {:keywords? true}) or similar. cljs-ajax doesn't allow using keywords in ajax-call to lookup response formats because that will defeat dead code elimination. I can see two options:

  1. Create an atom where people can set a default response format
  2. Change the reg-fx to be inside a function, and let people call it with a default response format as a parameter. This could also be extended to let people provide default interceptors and other default parameters in the request map.

I'm probably leaning towards 2, but interested in other feedback.

sveri commented 6 years ago

I would love to have that or at least be able to provide an interceptor that adds a default respone format. Usually in a web application you decide for one format once (being in a clojure environment it will most probably be transit) and then go with it for the rest of the applications life. It is cumbersome to have to provide it in every request one makes.