🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

express-uri-template

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-uri-template

Expand express.js style URI templates, similar to RFC 6570

0.1.0
latest
Source
npm
Version published
Weekly downloads
1.1K
-27.96%
Maintainers
1
Weekly downloads
 
Created
Source

express-uri-template

NPM NPM

express-uri-template is the reverse of express' application routing.

express:

/forum/:fid/thread/:tid + /forum/hello/thread/world = {"fid": "hello", "tid": "world"}

express-uri-template:

/forum/:fid/thread/:tid + {"fid": "hello", "tid": "world"} = /forum/hello/thread/world

Why?

So you can generate urls from templates.

When?

You can use it in the browser, e.g. to generate URLs for AJAX requests or links inserted into the DOM. You can also use it in Node.js, to generate URLs for HTTP redirects or links in generated HTML.

Install

Node.js:

npm install express-uri-template

Bower:

bower install express-uri-template

Use

Use object params:

var eut = require('express-uri-template');

var uri = eut('/forum/:fid/thread/:tid', {"fid": "hello", "tid": "world"});
console.log(uri); // -> /forum/hello/thread/world

Use Array params (aka req.params):

var eut = require('express-uri-template');

var uri = eut('/forum/*/thread/*', ["hello", "world"]);
console.log(uri); // -> /forum/hello/thread/world

Why the strange name?

This library is inspired by RFC 6570, except that it uses express' uri template syntax, and is much simpler.

Keywords

express

FAQs

Package last updated on 22 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts