https://github.com/eldoy/reqroute
HTTP Request router
https://github.com/eldoy/reqroute
Last synced: 6 months ago
JSON representation
HTTP Request router
- Host: GitHub
- URL: https://github.com/eldoy/reqroute
- Owner: eldoy
- Created: 2022-04-19T10:59:58.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T01:20:06.000Z (almost 2 years ago)
- Last Synced: 2025-10-24T15:34:31.400Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reqroute
Routing lookup for NodeJS web servers. Supports dynamic URLs.
### Install
```
npm i reqroute
```
### Usage
The routes support both `get` and `post` requests.
```js
var http = require('http')
var rekvest = require('rekvest')
var router = require('reqroute')
// Create routes
var routes = {
'get#/hello': 'hello',
'post#/project/create': 'project/create'
}
// NodeJS web server
var server = http.createServer(function(req, res) {
// Add pathname to request object
rekvest(req)
router(req, routes)
// If match, the value in the routes is found here
req.route // 'hello'
})
```
### Dynamic URLs
Requests support _dynamic URLs_.
The parts of the URL that should be dynamic is prefixed by an _underscore_:
```js
var routes = {
'get#/project/_project_link': 'project/show'
}
// Assume req.pathname is '/project/master'
var server = http.createServer(function(req, res) {
// Add pathname to request object
rekvest(req)
router(req, routes)
req.route // 'project/show'
req.params.project_link // 'master'
})
```
ISC Licensed. Enjoy!
Created by [Eldøy Projects](https://eldoy.com)