0

I'm in the initial stages of planning a REST api. I'm only interested in the read aspects of it for now. I'm having trouble with filters. As a hypothetical, this api is designed to serve "foo" products. Each foo product can have one or more "bar" items, and one or more "baz" items. The combination of foo/bar/baz is what makes the final product (and url) distinct, and is what I'm looking for. The url must be bookmarkable, and able to recreate the final configured product.

I considered this answer, but while they suggest using query parameters as filters, it doesn't really address how to do so when more than one filter is needed. Say, for example, I needed foo item "1", with bar items "1,3,4" and baz items "2,5". What is the most proper construction for this sort of request? I'm thinking 'foo/1/bar/1,3,4/baz/2,5' is problematic. Is it perhaps 'foo/1/bar/baz?bar=1,3,4&baz=2,5'? 'foo/1?bar=1,3,4&baz=2,5'? Do singletons all get to be part of the url, where multiples are relegated to the query parameters?

Community
  • 1
  • 1
Aron
  • 382
  • 1
  • 12

1 Answers1

0

You should avoid using comma in your URL as it's reserved word, so you might get into the trouble even though it might work well on your server.

I would try with %2C which is URL encoded value for comma.

zoran jeremic
  • 2,046
  • 4
  • 21
  • 47
  • Thanks for the response. I think I'm going to have to end up using query parameters to do what I'm trying to do, with the url encoded comma as you suggest. – Aron Jul 30 '15 at 15:42