Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bergos/uri-template-route
Conditional Express middleware calls using RFC6570 URI Templates
https://github.com/bergos/uri-template-route
Last synced: about 2 months ago
JSON representation
Conditional Express middleware calls using RFC6570 URI Templates
- Host: GitHub
- URL: https://github.com/bergos/uri-template-route
- Owner: bergos
- Created: 2017-11-06T22:07:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-06T22:09:19.000Z (about 7 years ago)
- Last Synced: 2024-08-09T09:39:12.206Z (6 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# uri-template-route
This package uses [URI Templates](https://tools.ietf.org/html/rfc6570) for conditional middleware calls.
## Usage
`uri-template-route` is a factory which returns new middlewares.
Call it with a URI Template and the middleware function, which should be conditionally called.
The template must be given as `String` or `uri-templates` object.
If the request URL matches the template, the middleware function is called.
Template variables will be assigned to `req.params`.```
const uriTemplateRoute = require('uri-template-route')const app = express()
app.use(uriTemplateRoute('/my-uri-template{?}', (req, res, next) => {
// will be only called if req.url matches the template
console.log(req.params)
})
```