Arg.js – Lightweight URL argument and parameter parser
github.com
github.com
http://www.stretchr.com/?name=Mat&company=Stretchr#?comment=123
should become http://www.stretchr.com/companies/Stretchr/users/Mat/comments/123
The URL now looks much nicer and more readable, and it also leads to organized hierarchy because of predictable URL patterns. So maybe the user wants to see the list of all users in the Stretchr company. So just from the URL they can determine that a good way to do that is probably by removing the end of the URL so that it is: http://www.stretchr.com/companies/Stretchr/users
Anyway, that's just my personal preference, but I think that query string style URL's should be avoided unless absolutely necessary and nicer REST style URL's should be used instead.If you have a one page app you can route all requests on the domain to one page, and then use Backbone logic to look at the REST style URL and show the correct view based on the URL.
But more and more I'm writing apps with no backend (Stretchr makes it easy to do so) in just HTML5 and JavaScript... and serving pages like that tends to be more difficult.
I use a simple web server (like Thru http://github.com/stretchr/thru) that doesn't do any routing or path parsing etc.
How would this be done using a RESTful url path? You have to use url params. If so, this seems to be a nice solution if your using a lot of params.
Assuming you were searching for computers with the following filters:
Manufacturer: Apple
Type: Laptop
You could represent that as: http://mystore.com/electronics/computers/manufacturer/apple/type/laptop
If you make your routing code (on either the frontend or the backend) robust enough then you will be able to support any number of filters in any order. http://mystore.com/electronics/computers/manufacturer/apple/type/laptop#?order=-price&size=medium
Also - the `#` is nice for when you don't want to reload the page.Edit: pretty cool how all the sibling comments are along the same lines :)
Edit: base, not bass...silly me.
Arg.js turns an object like this:
{
tags: ["one", "two", "three"],
deep: {
nested: {
objects: true
}
}
}
into this: #?tags[0]=one&tags[1]=two&tags[2]=three&deep.nested.objects=true