0

I'm currently building some custom filters for a web api. I thought of a custom query string that looks like in the following example:

http://localhost/api/users?filter=

age(min:18,max:45),explvl(atleast:60),classes(types:[golem,tank,dozer])

I didn't want to encode Json to Base64 on the clientside and I find this format much easier to read. Currently I get the filter query parameter back as string. The question I have is how to effectively transform this format to json and backwards if possible.

I'm also open for alternative solutions that achieve the same readability and provide a parser implementation.

Kieran Quinn
  • 1,085
  • 2
  • 22
  • 49
Sebastian Krogull
  • 1,468
  • 1
  • 15
  • 31
  • AFAIK `JSON` wont work as query string because of the `quotation marks` – Sebastian Krogull Jun 24 '16 at 09:58
  • There's a few types of invalid characters in there, how is this going to work without any form of encoding? Or am I misunderstanding the question? –  Jun 24 '16 at 10:00
  • why not just use "post" with normal filter object? (json as is) – Aleksey L. Jun 24 '16 at 10:03
  • @Aleksey: Because I have a `Pagination` mechanism that generates links for the previous and the next page. So I need to pass those filters with some sort of query string. I'm also no fan of using `HTTP POST` in cases I want to `GET` Data. – Sebastian Krogull Jun 24 '16 at 10:09
  • @JayMee: I tested the query string and I get it back without problems. – Sebastian Krogull Jun 24 '16 at 10:13
  • `GET` will always be kinda limited.. With `POST` you could put filter, pagination and any other stuff inside single "request" entity – Aleksey L. Jun 24 '16 at 10:27
  • Use encodeURIComponent and you will be fine. – Adrian Iftode Jun 24 '16 at 10:37
  • @Adrian: This would result in a string that is not human readable anymore. – Sebastian Krogull Jun 24 '16 at 10:41
  • Possible duplicate of [can WCF JSON WebService operation with non-string parameters be called from browser?](http://stackoverflow.com/questions/25526535/can-wcf-json-webservice-operation-with-non-string-parameters-be-called-from-brow) – Paul Sweatte Dec 05 '16 at 15:51

0 Answers0