rfc6570-uri-template
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

rfc6570-uri-template

RFC 6570 URI template parser

Getting started

import { parse } from 'rfc6570-uri-template';

const template = parse('http://www.example.com/users/{id}');
const url = template.expand({ id: 1 }); // http://www.example.com/users/1

Examples

url = parse('{controller}/{action}').expand({ controller: 'books', action: 'read' });
books/read

url = parse('foo{?query,number}').expand({ query: 'mycelium', number: 100 });
foo?query=mycelium&number=100

url = parse('X{#hello}').expand({ hello: 'Hello World!' });
X#Hello%20World!

url = parse('{+path:6}/here').expand({ path: '/foo/bar' });
/foo/b/here

url = parse('{list}').expand({ list: ['red', 'green', 'blue'] });
red,green,blue

url = parse('{keys}').expand({ keys: { semi: ';', dot: '.', comma: ',' } });
semi,%3B,dot,.,comma,%2C

url = parse('{keys*}').expand({ keys: { semi: ';', dot: '.', comma: ',' } });
semi=%3B,dot=.,comma=%2C

See more examples in the RFC 6570 specification.

GitHub · NPM package

Readme

Keywords

Package Sidebar

Install

npm i rfc6570-uri-template

Weekly Downloads

77

Version

1.1.0

License

Apache-2.0

Unpacked Size

42.8 kB

Total Files

6

Last publish

Collaborators

  • teil-one