GET request with nested JSON object


When performing a GET request with a nested JSON parameter, its value is being serialised into a string, which then needs to be parsed in the Rails backend:

Started GET "/api/data/index.json?query=%7B%22term%22:%22abc%22,%22paginated%22:true%7D" for ::1 at 2017-07-07 14:56:29 +1000
Processing by Api::DataController#index as JSON
  Parameters: {"query"=>"{\"term\":\"abc\",\"paginated\":true}", "datum"=>{}}

Is there a way to serialise the request like a POST? What I wanted is what a browser does when submitting the same URL (http://localhost:3000/api/data/index?query={term:‘abc’,paginated:true}). The server receives a hash instead of a string:

Started GET "/api/data/index?query={term:'abc',paginated:true}" for ::1 at 2017-07-07 15:00:44 +1000
Processing by Api::DataController#index as HTML
  Parameters: {"query"=>"{term:'abc',paginated:true}"}

Googling this subject I found that Angular.js previously offered an alternative serializer, $httpParamSerializerJQLike, but that doesn’t seem to be the case for Angular2 anymore? Also, I couldn’t figure how this could be used in Ionic, as the Http object is injected and there’s no documentation on how to configure it?

Any help on the subject is appreciated…

Thanks, Ricardo

There is a standard syntax for URL query strings used across the web. Why don’t you want to use it?


Hi rapropos, thanks for the quick answer. I believe I’m using it, the problem is that the value of the parameter is itself an object. So another example would be:

api/whatever?param={id:1,kind:'abc',innerobjects:[{prop1:'something else',prop2:9999},{prop1:'another',prop2:2212}]}

The main point here is that it’s not possible to disassemble the object’s properties into parameters, as they are nested…


I wish you the best of luck with this, but if I were in your shoes I would redesign the API so that such complex query strings are not needed. There seems to be just too much possibility here for not just complexity in writing and testing the app, but also securing it from malicious access.

Thanks for the suggestion, I just wanted to make sure there’s currently no alternative for ionic 2, as the $httpParamSerializerJQLike approach would solve the problem without requiring redesigning the API…