Hacker News new | ask | show | jobs
by alexchamberlain 5136 days ago
This looks interesting, I wonder whether the path syntax would work in URLs.
1 comments

Can you unpack that question a little for me? As in, could you use a spahql selection as the path component of some request? I don't see why not, but the escaping will probably look a little ugly.
Given a url that returns JSON:

  www.example.com/data.json,
one could append SparQL to select a subset

  www.example.com/data.json/user

  www.example.com/data.json/categories/*

  www.example.com/data.json/categories/0/products

  www.example.com/data.json//avatar
The only small issue I can see with that is identifying where the path to the resource ends and where the query to applied to the JSON representation of the resource starts.

Perhaps something like:

    www.example.com/data.json?query=/user
A webserver could easily figure that out, as long as it is configured correctly and with knowledge of the domain. I don't like using query strings like this, as it makes the URL point to multiple objects.
I'm not sure it could, if I have a resource with a URL:

    www.example.com/foo
and it can arbitary sub-resources e.g.

    www.example.com/foo/bar/raz
then how do I know whether bar is a different resource or part of the JSON returned describing www.example.com/foo

This would mean you'd have to restrict your resource names to ensure they don't clash with JSON names - which seems a pain (e.g. say the resource names are uploaded files and directories, so you won't have much control over what they are called)

Replying to the reply to this- I am pretty sure the webserver can easily find out that foo is a JSON file when resolving the path. Most operating systems don't let you name a file and a directory the same thing, so the file system API knows straight away there is no such directory named "foo", and can have special handling for whatever kind of file "foo" happens to be. (in this case, JSON)
That's a pretty interesting idea, and I see no reason why it shouldn't work.