Live data from Hacker News

JSON in URLs

blogs.dropbox.com

11–20 of 38 posts

Re: JSON in URLs

#11

Earlier quoted context omitted.

This is already a problem if you ever have to work with non-ASCII characters. Check out a URL to a page in the Japanese Wikipedia, for instance.

http://ja.wikipedia.org/wiki/ベーカーストリート・アンド・ウォータールー鉄道

Or, as it shows up for me, http://ja.wikipedia.org/wiki/%E3%83%99%E3%83%BC%E3%82%AB%E3%...

Re: JSON in URLs

#12

Earlier quoted context omitted.

This is already a problem if you ever have to work with non-ASCII characters. Check out a URL to a page in the Japanese Wikipedia, for instance.

http://ja.wikipedia.org/wiki/ベーカーストリート・アンド・ウォータールー鉄道

Ahh but that is not the value that is sent to the webserver, that is just your web browser prettying up the display. If we open the inspector and see what was sent we have:

Request URL:https://ja.wikipedia.org/wiki/%E3%83%99%E3%83%BC%E3%82%AB%E3...

Your browser will equally pretty up the json in the url for display purposes.

Re: JSON in URLs

#13

When I pass around any parameters in GET or POST parameters I wrap them in base64. That makes a lot of escaping bugs go away (and adds a bit of "security by obscurity", as well as true security when combining the query with a random number, a sha256 hash of the parameters and a serverside secret).

Not that this matters to your overall point, but base64 isn't actually a valid format to use in a parameter as a base64 string can legally contain: '+', '/' and '=' which would be interpreted and corrupt the data.

In the .Net world you'll want to use something like HttpServerUtility.UrlTokenEncode()/UrlTokenDecode() since it gives you a base64-like string with '+', '/' and '=' replaced or removed.

Re: JSON in URLs

#15

When I pass around any parameters in GET or POST parameters I wrap them in base64. That makes a lot of escaping bugs go away (and adds a bit of "security by obscurity", as well as true security when combining the query with a random number, a sha256 hash of the parameters and a serverside secret).

We're getting pretty far off-topic here, but please note that "a sha256 hash of the parameters and a serverside secret" is insufficient for authentication: http://en.wikipedia.org/wiki/Hash-based_message_authenticati...

Re: JSON in URLs

#16

When I pass around any parameters in GET or POST parameters I wrap them in base64. That makes a lot of escaping bugs go away (and adds a bit of "security by obscurity", as well as true security when combining the query with a random number, a sha256 hash of the parameters and a serverside secret).

I find those URLs massively ugly.

Re: JSON in URLs

#17

When I pass around any parameters in GET or POST parameters I wrap them in base64. That makes a lot of escaping bugs go away (and adds a bit of "security by obscurity", as well as true security when combining the query with a random number, a sha256 hash of the parameters and a serverside secret).

Sounds like some pretty crappy hand rolled security to me. Don't ever think of something as secure unless it actually is a secure protocol. You are wasting your time and your code is probably exploitable.

Re: JSON in URLs

#18
I designed something similar while writing scoutcamp (an express.js competitor). I made it so that it could parse both normal queries (eg, `?age=12&cards=visa&cards=mastercard`) and JSON (eg, `?age=12&cards=["visa","mastercard"]`).

I'd argue that design is easier to read and allows graceful degradation: someone using an API with fields `age` and `cards` can rely on the traditional way to work. They can easily reformulate their query when more complex structures are required. Yet Ajax scripts can use a simple shim to make XHR calls that send arbitrary JSON data.

https://github.com/espadrine/sc/blob/master/lib/camp.js#L82

Re: JSON in URLs

#19
I'm all for (ab)using specs whenever convenient, but this is just such a bad idea.

You will rarely actually use query args (ie ?x=y&foo=1) with a true REST API anyway. Use your resource path and avoid query args except for idempotent GET operations. If you have complex data, just put it in a request body as JSON. Don't put that crap in a query arg. That's not what it's for.

Re: JSON in URLs

#20
May I recommend the following blog post:

http://blog.lunatech.com/2009/02/03/what-every-web-developer...

and the HN discussion of that post:

https://news.ycombinator.com/item?id=5930494

I used JSON in the URL to preserve the state of a report across reloads. I kind of regret it, because it wouldn't have been that much work to maintain a URL with normal query args. I think I had in mind that JSON would better handle things like the collapse/expand state of nested groups (a tree, essentially), but mostly I was just lazy, considering that I never got that far.

Post reply on HN