Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aslakhellesoy/express-uri-template
Expand express.js style URI templates, similar to RFC 6570
https://github.com/aslakhellesoy/express-uri-template
Last synced: about 1 month ago
JSON representation
Expand express.js style URI templates, similar to RFC 6570
- Host: GitHub
- URL: https://github.com/aslakhellesoy/express-uri-template
- Owner: aslakhellesoy
- License: mit
- Created: 2013-06-21T18:07:48.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-22T17:29:39.000Z (almost 11 years ago)
- Last Synced: 2024-04-15T11:41:31.907Z (8 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# express-uri-template
[![NPM](https://nodei.co/npm/express-uri-template.png?stars&downloads)](https://nodei.co/npm/express-uri-template/)
[![NPM](https://nodei.co/npm-dl/express-uri-template.png)](https://nodei.co/npm/express-uri-template/)express-uri-template is the reverse of [express' application routing](http://expressjs.com/api.html#app.VERB).
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:
```javascript
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`):
```javascript
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](http://tools.ietf.org/html/rfc6570), except that it uses express'
uri template syntax, and is much simpler.