0

I have a Web API program that has 8 get methods.

Each method can get 2 parameters - filters and sorts.

  • filters - a json object that contains all the params you can filter by
  • sorts - an array that contains all the properties you want to sort by

For example:

www.facebook.com/GetFriends?filters={name:"lior", color:{name:"blue", RGB:{255, 100, 0}}}&sorts=[{prop:"name", desc:true}, {prop:"age", desc:false}]

The api's only available from other servers, so there's no need to worry about URL characters limit in browsers.

We chose GET method because the purpose of this api is only to get data.

I'm not sure the url we require is in a 'normal' format-

Is that okay in a GET method to use a two query params that one of them is json and the other is array?

Thank you for your help

Federico Dipuma
  • 17,655
  • 4
  • 39
  • 56
  • 1
    Please try running your code before posting. – poppertech Jun 02 '16 at 20:21
  • 1
    Using json as query string parameter value is truly a bad choice. First thing to consider: json must be encoded if put in the URI. I suggest you to flatten you objects and make them simple query strings key/value pairs. Avoid using JSON at all costs. – Federico Dipuma Jun 02 '16 at 20:33
  • No, that will not work out of the box. If you have complex data you want to pass it would be better to change it to a POST method and except data from the message body instead of the uri. Then you could pass it as json. Alternatively you can write a bunch of code to force it to work the way you want but it is not worth the trouble or maintenance that follows when there is an easy alternative. – Igor Jun 02 '16 at 20:35
  • It works, but i'm asking for help to understand the standart. I know i can use POST but my api purpose is only to get data, without inserting or updating. – Lior Dolev Jun 03 '16 at 09:01
  • Here you may find what you need: http://stackoverflow.com/questions/12916340/complex-type-is-getting-null-in-a-apicontroller-parameter – Fabricio Apr 18 '17 at 16:27

0 Answers0