Uri

APINetworkingUri

Source

Uri::constructor(uri)

Parameters:
  • uri — String

Represents an uri string with parameters.

The parameter must be wrapped by the curly brackets {…}.

Rest parameters are not greedy and are wrapped by the {…*} or just …*. Rest parameters don't have to be named ({*} is allowed).

var uri = new Networking.Uri('articles/{pageStart}/{pageEnd}');
console.log(uri.match('articles/2/4'));
// { pageStart: '2', pageEnd: '4' }

var uri = new Networking.Uri('comments/{path*}/{page}');
console.log(uri.match('comments/article/world/test-article/4'));
// { path: 'article/world/test-article', page: '4' }

Access it with:

var Networking = require('networking');
var Uri = Networking.Uri;

Source

Uri::protocol

Type:
String

Uri::auth

Type:
String

Uri::host

Type:
String

Uri::path

Type:
String

Uri::params

Type:
Object

Holds the last Uri::match() result.

Uri::query

Type:
Object

Uri::hash

Type:
String

Uri::test(uri)

Parameters:
  • uri — String
Returns:
Boolean

Test whether the uri is valid with the given string.

Source

Uri::match(uri)

Parameters:
  • uri — String
Returns:
Object

Returns found parameters from the given string.

If the given uri is not valid with the uri, error will be raised.

Source

Uri::toString(params)

Parameters:
  • params — Object|Dictoptional
Returns:
String

Parses the uri into a string.

The given params object is used to replace the uri parameters.

var uri = new Networking.Uri('user/{name}');

console.log(uri.toString({name: 'Jane'}));
// /user/Jane

console.log(uri.toString());
// /user/{name}

Source