News for hackers. Stuff that matters.
Re:SpahQL - A query language for Javascript objects by angryamoeba on Monday May 21, 2012 @06:42AM (#4002189)
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.
Re:SpahQL - A query language for Javascript objects by alexchamberlain on Monday May 21, 2012 @06:59AM (#4002227)
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
Re:SpahQL - A query language for Javascript objects by arethuza on Monday May 21, 2012 @07:38AM (#4002335)
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
Re:SpahQL - A query language for Javascript objects by alexchamberlain on Monday May 21, 2012 @07:44AM (#4002366)
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.
Re:SpahQL - A query language for Javascript objects by arethuza on Monday May 21, 2012 @08:05AM (#4002430)
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)

Re:SpahQL - A query language for Javascript objects by ZenPsycho on Monday May 21, 2012 @08:17AM (#4002473)
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)
Re:SpahQL - A query language for Javascript objects by angryamoeba on Monday May 21, 2012 @07:12AM (#4002270)
That's a pretty interesting idea, and I see no reason why it shouldn't work.