UNPKG

uri-template-router

Version:

Match a URI to a pattern in a collection of URI Templates

200 lines (199 loc) 5.13 kB
[ { "label": "substring match", "templates": [ "http://{authority}/" ], "uris": { "http://example.com/": { "authority": "example.com" }, "http://example.org/": { "authority": "example.org" }, "http://www.example.net/": { "authority": "www.example.net" }, "https://example.com/": null } }, { "label": "encoded match", "templates": [ "http:{+hierpart}" ], "uris": { "http://example.com/": { "hierpart": "//example.com/" }, "http://example.org/": { "hierpart": "//example.org/" }, "http://www.example.net/": { "hierpart": "//www.example.net/" }, "https://example.com/": null, "urn:uuid:foo": null } }, { "label": "extension/suffix determination", "templates": [ "http://localhost/{document_any}", "http://localhost/{document_txt}.txt", "http://localhost/{document_html}.html", "http://localhost/{document_json}.json" ], "uris": { "http://localhost/about": { "document_any": "about" }, "http://localhost/about.txt": { "document_txt": "about" }, "http://localhost/about.html": { "document_html": "about" }, "http://localhost/about.json": { "document_json": "about" } } }, { "label": "extension/suffix determination 2", "templates": [ "/a/{any}", "/a/{txt}.txt" ], "uris": { "/a/pg": { "any": "pg" }, "/a/pg.txt": { "txt": "pg" } } }, { "label": "extension/suffix determination 3 (reverse order)", "templates": [ "/b/{txt}.txt", "/b/{any}" ], "uris": { "/b/pg": { "any": "pg" }, "/b/pg.txt": { "txt": "pg" } } }, { "label": "path with explode modifier (ideal match)", "templates": [ "http://a.local{/path*}" ], "uris": { "http://a.local": {}, "http://a.local/": { "path": [ "" ] }, "http://a.local/a": { "path": [ "a" ] }, "http://a.local/a/": { "path": [ "a", "" ] }, "http://a.local/a/b": { "path": [ "a", "b" ] }, "http://a.local/a/b/": { "path": [ "a", "b", "" ] }, "http://a.local/a/b/c": { "path": [ "a", "b", "c" ] }, "http://a.local/a/b/c/": { "path": [ "a", "b", "c", "" ] }, "http://a.local/a/b/c/d/e": { "path": [ "a", "b", "c", "d", "e" ] }, "http://a.local/a/b/c/d/e/": { "path": [ "a", "b", "c", "d", "e", "" ] } } }, { "label": "path with explode modifier (no match)", "templates": [ "http://a.local{/path*}" ], "uris": { "http://a.local!": null, "http://a.local/!": null, "http://a.local/a!": null, "http://a.local/a/!": null, "http://a.local/a/b!": null, "http://a.local/a/b/!": null, "http://a.local/a/b/c!": null, "http://a.local/a/b/c/!": null, "http://a.local/a/b/c/d/e!": null, "http://a.local/a/b/c/d/e/!": null } }, { "label": "path with explode modifier with fixed route", "templates": [ "http://b.local/", "http://b.local{/path*}" ], "uris": { "http://b.local": {}, "http://b.local/": {}, "http://b.local/a": { "path": [ "a" ] } } }, { "label": "path", "templates": [ "http://c.local{/path*}" ], "uris": { "http://c.local": {}, "http://c.local/": { "path": [""] }, "http://c.local/a": { "path": [ "a" ] } } }, { "label": "blog example 1", "templates": [ "http://example.com/", "http://example.com/root{/base}{/dir*}", "http://example.com/blog{/y,m,d,slug}" ], "uris": { "http://example.com/": {}, "http://example.com/root": { }, "http://example.com/root/base/b/c": { "base":"base", "dir": [ "b", "c" ] } } }, { "label": "htindex", "templates": [ "http://example.com/", "http://example.com{/a*}/", "http://example.com{/b*}" ], "uris": { "http://example.com/": {}, "http://example.com/root": { "b": ["root"] }, "http://example.com/root/": { "a": [ "root" ] } } }, { "label": "blog example 2", "templates": [ "http://example.com/", "http://example.com/root{/base}{/a*}", "http://example.com/blog{/y,m,d,slug}" ], "uris": { "http://example.com/": {}, "http://example.com/root": { }, "http://example.com/root/base": { "base":"base" }, "http://example.com/root/base/": { "base":"base", "a": [ "" ] }, "http://example.com/root/base/b": { "base":"base", "a": [ "b" ] }, "http://example.com/root/base/b/": { "base":"base", "a": [ "b", "" ] }, "http://example.com/root/base/b/c": { "base":"base", "a": [ "b", "c" ] } } }, { "label": "multilevel", "templates": [ "http://example.com/", "http://example.com/a/b/c", "http://example.com/a/b{/c}", "http://example.com/a{/b}{/c}", "http://example.com{/a}{/b}{/c}" ], "uris": { "http://example.com/": { }, "http://example.com/a": { }, "http://example.com/a/": { }, "http://example.com/a/2": { "b":"2" }, "http://example.com/a/b": { }, "http://example.com/a/b/": { }, "http://example.com/a/b/c": { }, "http://example.com/a/2/3": { "b":"2", "c":"3" }, "http://example.com/1/2/3": { "a":"1", "b":"2", "c":"3" } } }, { "label": "pct-encoded characters", "templates": [ "{expr}" ], "uris": { "": { }, "foo": { "expr": "foo" }, "%20": { "expr": " " }, "%25": { "expr": "%" } } } ]