0

I have a web app that loads data sources from provided GET parameters. The application can take any number of data sources, such as:

mysite.com/?feed=http://foo.com&feed=http://bar.com

These feed values can be URL encoded or not. My app polls these data sources at a given interval. I'd like to allow the user to optionally enter a polling interval via another GET param.

What's the proper way to provide a GET parameter that relates to another GET parameter? I'm thinking of using commas:

mysite.com/?feed=http://foo.com,interval=1&feed=http://bar.com,interval=5

In my application, I would parse the values and detect that interval=5 would relate to feed=http://foo.com. Something about this seems a bit smelly. I don't know if I've ever seen this done before. Are commas a bad idea?

Note: It is possible for a feed to NOT have a corresponding interval (relying on an internal default instead). Consider the following:

mysite.com/?feed=http://foo.com,interval=1&feed=http://blah&feed=http://bar.com,interval=5
alukach
  • 4,843
  • 3
  • 37
  • 38

1 Answers1

1

I personally prefer passing data like this as an array:

mysite.com/?feed[]=http://foo.com&interval[]=1&feed[]=http://bar.com&interval[]=5

You would then establish correspondence between the different feed-interval pairs through their common indices in the respective arrays.

This answer has some excellent examples: https://stackoverflow.com/a/9547490

Community
  • 1
  • 1
bers
  • 3,714
  • 1
  • 32
  • 44
  • Ah, interesting, although I don't think that this is exactly what I'm looking for. I should have mentioned that some `feed` values might not have an `interval`, which throws somewhat of a kind into this plan. Updating my question... – alukach Jun 16 '15 at 01:21
  • You could still pass a 0 or -1 as a default argument; but I agree, other options are probably better in this particular case. – bers Jun 16 '15 at 10:20