A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rezigned/uri-template.js below:

rezigned/uri-template.js: Node.js/Javascript RFC 6570 URI Template implementation that supports both URI expansion and extraction.

Node.js/Javascript RFC 6570 URI Template implementation that supports both URI expansion and extraction.

A very simple usage

UriTemplate.expand('/{username}/profile', {'username': 'john'});

>> '/john/profile'

More examples (supports all expansion levels defined in RFC6570)

UriTemplate.expand('/search/{term:1}/{term}/{?q*,limit}', {
    term: 'john',
    q: ['a', 'b'],
    limit: 10,
});

>> '/search/j/john/?q=a,b&limit=10'

Extract variables from URI.

UriTemplate.extract('/search/{term:1}/{term}/{?q*,limit}', '/search/j/john/?q=a&q=b&limit=10');

>>
(
    'term:1': 'j',
    term: 'john',
    q: [
      'a',
      'b'
    ]
    limit: 10
)

You can also instantiate UriTemplate instance via new keyword. Its constructor accepts 2 optional params base uri and default params. Which is very useful when working with API endpoint.

var uri = new UriTemplate('https://api.twitter.com/{version}', {'version': 1.1});
uri.expand('/statuses/show/{id}.json', {'id': '210462857140252672'});

>> https://api.twitter.com/1.1/statuses/show/210462857140252672.json

In browsers:

bower install uri-template.js
<script src="dist/uri-template.js"></script>
UriTemplate.expand(...)

In Node.js

npm install uri-template.js

UriTemplate = require('uri-template.js');

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4