I am totally against the use of serialized JSON inside the query string of a URI, for several reasons:
- It makes the URI not human-readable (encoded brackets and whitespaces generates horrible query strings)
- It makes the parameter not composable (to add another "filter" you'll have to unencode the JSON, deserialize it into an object, add the new field, and then again serialize + encode)
- It creates long URIs for no benefit (again, encoded parts of your JSON unnecessary make the query string grow)
Even if you could use POST for such a purpose, I believe it would be semantically more correct to keep using GET if you intend to only query data, without modifying it.
In many situations like the one you described I simply converted my complex object to separated query string parameters, creating URIs like this one:
http://myhost.com/query?filters.fieldName1=fieldValue1&filters.fieldName2=fieldValue2&sort=fieldName&sortDirection=asc&page=2&pageSize=3
You may easily parse this query string in ASP.NET Web Api 2 (I suppose you are using this framework because of the tag inside your question) using a custom ModelBinder
for a custom Paging
object that contains any data you require to execute your query server-side.
As an alternative approach you could consider putting those parameters inside a custom (or multiple) request header, and then read them server-side:
X-Query-Filter: FieldName1=FieldValue1&FieldName2=FieldValue2
X-Query-Sort: FieldName
X-Query-Sort-Direction: ASC
X-Query-Page: 2
X-Query-PageSize: 3