-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Vitaly Tomilov edited this page Jul 19, 2018
·
75 revisions
The URL spec extends on RFC 3986, by adding the following:
- Multiple-hosts support, in the form of
hostA:123,hostB:456,hostC:789
- Supports Unicode symbols within the
protocol
section
See also: Frequently Asked Questions.
The connection-string
protocol is ultimately flexible, and allows everything to be optional.
See from examples below how various parameters can be passed in, while skipping others.
ends with ://
parse('abc://'); //=> {protocol: 'abc'}
parse('my%20protocol://'); //=> {protocol: 'my protocol'}
parse('abc://server:12345');
/* => {
protocol: 'abc',
hosts: [{name: 'server', port: 12345, isIPv6: false}]
}*/
parse('server:12345');
/* => {
hosts: [{name: 'server', port: 12345, isIPv6: false}]
}*/
parse('server');
/* => {
hosts: [{name: 'server', isIPv6: false}]
}*/
starts with :
, followed by digits
parse(':12345');
/* => {
hosts: [{port: 12345}]
}*/
ends with @
parse('username@'); //=> {user: 'username'}
starts with :
and ends with @
parse(':pass123@'); //=> {password: 'pass123'}
starts with /
parse('/one/two'); //=> {path: ['one', 'two']}
starts with ?
parse('?param1=value1¶m2=value2');
/* => {
params: {
param1: value1,
param2: value2
}
}*/
parse('abc:///one/two');
/* => {
protocol: 'abc',
path: ['one', 'two']
}*/
parse('abc://?param1=one¶m2=two');
/* => {
protocol: 'abc',
params: {
param1: 'one',
param2: 'two'
}
}*/
parse('name@?param1=one¶m2=two');
/* => {
user: 'name',
params: {
param1: 'one',
param2: 'two'
}
}*/
parse('name@/first/second');
/* => {
user: 'name',
path: ['first', 'second']
}
}*/
The list of examples above shows only the most interesting cases, but you can combine them as you like, and the parser will recognize all the right parameters.