0.1.4 • Published 11 months ago

reqroute v0.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Reqroute

Routing lookup for NodeJS web servers. Supports dynamic URLs.

Install

npm i reqroute

Usage

The routes support both get and post requests.

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:

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

0.1.4

11 months ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago