URL per directory query-string
I am building a web framework which is based on a hierarchical modular design. I've got components and components extending other components.
To access these components I'm looking for a nice syntax in the URL. As I'm using Node.js, I've got no restrictions whatsoever from existing web server software. Components are simply structured objects in JavaScript that can be piped together.
The URL scheme I use is:
/componentA/componentBextendsA/componentCextendsB
Now, I want to give each component it's own parameters. Intuitively I wanted to do this with directory-based query-strings, like:
/componentA?foo=bar&hello=world/componentB?foo=test/componentC?pie=
- componentA
foo
=bar
hello
=world
- componentB
foo
=test
- componentC
pie
= empty
The arguments can overlap, as one component can handle the same query parameter as the other.
My questions are:
- can clients break because of this?
- is there an already existing implementation of开发者_如何学JAVA directory-query-strings?
From the URI component perspective, the URI /componentA?foo=bar&hello=world/componentB?foo=test/componentC?pie=
consists of the path /componentA
and the query foo=bar&hello=world/componentB?foo=test/componentC?pie=
. And inside the query component, both /
and ?
are valid plain characters. So this URI should be handled correctly by clients.
If you want to parse this URI the way you’ve described, you can do the following:
var url = "/componentA?foo=bar&hello=world/componentB?foo=test/componentC?pie=";
var re = /([^?]+)(?:\?([^?\/]*))/g, match, components = [];
while (match = re.exec(url)) {
components.push({path: match[1], query: match[2]});
}
I think that doesn't a good idea. Current trend is to simplify urls, for clarity and because SEO. I don't know if that actually works, but pasing parameter in the ?var=value
format is being deprecated. I developed my own php framework, maybe I could give some ideas if you give me more info. (Sorry about my english)
精彩评论