Fork me on GitHub

 (fn [{:keys [db]} _]
   {:http-xhrio {:method :get
                 :uri ""
                 :params {:request @(rf/subscribe [:request])
                          :constraints @(rf/subscribe [:constraints])}
                 :response-format (ajax/json-response-format {:keywords? true})
                 :on-success [:success-http-result]
                 :on-failure [:failure-http-result]}}))
Hello, I have a event that makes a database call as shown. I believe there are issues with what I am doing in the :params . May I know what should I be doing instead of :constraints @(rf/subscribe [:constraints])} ? Do I need to write it as json first? Am thinking I am doing something wrong as it seems my constraints map in the re-frame db ...
[{:name "Land Take"
  :constraint :land-take
  :details {:min "100", :max "500"}}
 {:name "Total GFA"
  :constraint :land-gfa
  :details {:min "100", :max "500"}}]
seems to be passed as
{:name ["Land Take" "Total GFA"]
 :constraint ["land-take" "total-gfa"]
 :details {:min ["100" "100"], :max ["500" "1000"]}}


First of all, don't use subscribe inside event handlers: Second of all, IIRC :params is a map which for :get requests without any request format will be converted into query parameters, so the values there must be plain scalars, like numbers, strings, etc.


Ah, my bad - seems like the values can be vectors. By default, {:a [1 2]} will be converted into a=1&a=2.


Right, so I should use the 3rd party library?


I simply wouldn't use subscriptions there at all. Just extract the values from the db directly.


Meaning ... {:filter request constraints] ?


I have no idea what you mean by that. Given the DB above, what query string do you want to get?


{:constraints [{:name "Land Take"
                :constraint :land-take
                :details {:min "100", :max "500"}}
               {:name "Total GFA"
                :constraint :land-gfa
                :details {:min "100", :max "500"}}]
 :request nil}
My db is like this? I want both :constraints and :request I don't quite understand what you mean by "Just extract the values from the db directly"


I was trying to ask if you mean for me to pass the data to the my filter event like {:filter request constraints]


How do you expect :constraints to be represented in a query string?


I was hoping there would be a way to translate :constraints as it is, like

[{:name "Land Take"
  :constraint :land-take
  :details {:min "100", :max "500"}}
 {:name "Total GFA"
  :constraint :land-gfa
  :details {:min "100", :max "500"}}]
or a way for me to perhaps write to json and read such that my backend receives the data such a format


There are many such ways. I'd argue that query string is not a good fit here. If you have control over the type of the response you can use, switch from GET to POST and just encode it as regular Transit.


so a content-type of {"Content-type" "application/transit+json"} ?