URI handling in JavaScript with b9j.uri

grink on 2008-09-04T18:47:50

Following my b9j.path release, I just finished up work on URI object-class for javascript.

It uses Steven Levithan's parseUri 1.2 to do the parsing.

Some example usage:

var uri = new b9j.uri.URI( "http://example.com/a/b?a=1&b=2&c=3&c=4&c=5" )
var host = uri.host()

var child = uri.child("c.html")            // http://example.com/a/b/c.html?a=1&b=2& ...
child.query().add({ c: [ 6, 7 ], d: 8 })   // ... ?a=1&b=2&c=3&c=4&c=5&c=6&c=7&d=8
child.query().set("b", 9)                  // ... ?a=1&b=9&c ...

return child.toString()

Again, while CPAN has URI.pm for URI-handling, JavaScript didn't really have an equivalent (parsing yes -- modifying/generating no).

b9j.uri - URI parsing, manipulation, and generation

URI handling in JavaScript with b9j.uri: a URI/URI-query parser, manipulator, and generator


js-uri

Dom2 on 2008-09-06T08:42:00

I did write js-uri once, but I don't know how useful that is to you... It was mostly an exercise in implementing the URI resolution algorithm in RFC3986.

Re:js-uri

grink on 2008-09-11T23:40:59

Yeah, I saw that while doing some research. Looked like a good crack at URI parsing, but ultimately I went with Steven Levithan's parseUri:

http://blog.stevenlevithan.com/archives/parseuri

My take was an exercise in wrapping the parser and providing methods to access/update the path, query, etc.

I've put up an interactive example here (which will show you the code at the same time):

http://appengine.bravo9.com/b9j/example/uri/