gazetteerhk / census_explorer

Explore Hong Kong's neighborhoods through visualizations of census data
http://gazetteer.hk
MIT License
42 stars 12 forks source link

Style of parameters in API query string #33

Closed hupili closed 10 years ago

hupili commented 10 years ago

After making a test app, we find that current query string can be too long due to repeated occurrences of keys. Another issues is the string does not read semantically smooth.

table=18&area=a01 is clear. The two filtering conditions are logically and-ed. (aka originally meaning of &)

When we write table=18&area=a01&area=a02, we actually mean table=18 & (area=a01 | area=a02). area=a01,a02 or area=a01|a02 reads better. Same for return.

The glitch is more obvious when it comes to zero v.s. non-zero number of occurrences. Without area, it means to return data of all areas. With one area, it suddenly filters down to one area. The change from & to &area=a01 to &area=a01&area=a02 is not so smooth. Using the , style, the change from &area= to &area=a01 to &area=a01,a02 ... to & (do not filter), is smooth.

hxu commented 10 years ago

I suppose I have no strong preference one way or the other. The only thing was that the $http service on the front end automatically encoded it like area=a01&area=a02. It should be easy to send as comma separated.

If you think that comma separated (or pipe separated) is better, then we can go ahead and do that.

hupili commented 10 years ago

Yesterday when coding the sample app with @vincentlaucy and @2blam , we find that comma separated list is more intuitive. I prefer to use , to make it more compact.

hxu commented 10 years ago

Ok, let's do it then. On Feb 10, 2014 9:55 PM, "HU, Pili" notifications@github.com wrote:

Yesterday when coding the sample app with @vincentlaucyhttps://github.com/vincentlaucyand @2blam https://github.com/2blam , we find that comma separated list is more intuitive. I prefer to use , to make it more compact.

— Reply to this email directly or view it on GitHubhttps://github.com/hxu/hk_census_explorer/issues/33#issuecomment-34633308 .

hupili commented 10 years ago

closed by pull #34

hxu commented 10 years ago

Do you think it is more correct to url encode first, then join with commas, or join with commas first, then url encode (i.e. should the commas be escaped)? Of course it is more readable if we do not escape the commas, so I think that is preferable, unless there are some edge cases I am not thinking of?

hupili commented 10 years ago

I prefer non-encoded comma. As for content, I have checked that we don't have comma in identifiers, so the direct frontend join and backend split should be OK.