0

I wrote a web service providing some HTTP routes, one of which is structured like so:

/grid/get-foos?filters={"type": ["bar"], "status": ["baz", "qux"]}

The filters parameter is a serialized JSON object. There is a set of acceptable keys, and each of those keys' values should be an array, as above. I'm trying to filter get-foos, returning only foos which suit the criteria in filters. The above reads "give me foos with type bar AND with status baz OR qux".

Somebody on my team told me that serializing JSON this way and sticking it in the query string is non-standard. Is it? I'm new at this.

What is the most idiomatic way (or even just a good way) to structure API calls that filter a "getter" like this?

edit: should have mentioned, this is written in clojure with ring and compojure.

Cody Canning
  • 176
  • 3
  • 14

2 Answers2

1

I'd recommend you use next way:

 /grid/get-foos?types[]=bar&statuses[]=baz&statuses[]=qux

But keep in mind: you should have a framework that can accept this type of params.

Arsen
  • 10,815
  • 2
  • 34
  • 46
0

Inspired by @Arsen I've discovered compojure supports repeating parameters, see here: How to get repeating request parameters in Compojure

I'm still wondering if what I did originally is non-standard... and/or bad?

Community
  • 1
  • 1
Cody Canning
  • 176
  • 3
  • 14