UriManager

UriManager

Parses URI with awareness of local resources.

Knows about the different resource endpoints and can parse URIs returning the type of resource and any useful parameters. It can also construct URIs based on type and parameters.

Constructor

new UriManager(base)

Constructor.

Parameters:
Name Type Description
base String

Should correspond to the public base URI.

Source:

Methods

addResource(type, path)

Register a new resource type.

This is called initially during startup to define the different resources and their corresponding URI endpoints.

Parameters:
Name Type Description
type String

Type of resource.

path String

Path (route) for this resource, e.g. '/foos/:id'

Source:

make(type, …params) → {String}

Create a new URI based on a type and ordered parameters.

Parameters:
Name Type Attributes Description
type String

Type of URI

params * <repeatable>

List of values to fill in to URI parameters

Source:
Returns:

Complete, absolute URI

Type
String

makeWithParams(type, params) → {String}

Create a new URI based on a type and ordered parameters.

Parameters:
Name Type Description
type String

Type of URI

params Object

Parameters to fill in

Source:
Returns:

Complete, absolute URI

Type
String

parse(uri, requiredType) → {Object}

Determines if a URI matches any local resource.

This method will compare a URI first against the local base URI to determine if it is a local URI at all. Then, it will compare it against all registered local resource URI types. If any match it will parse the URI and return an object with information about the type of resource and any parameters that were included in the URI.

Parameters:
Name Type Description
uri String

URI to be parsed/analyzed

requiredType String

If provided, URI must be of this type or an error is raised.

Source:
Returns:

Description of the URI with contextual information.

Type
Object