Stats

 Latest version : 2.0.0

 Last updated on 2018-08-07T18:38:02.638Z

 Keywords : router, connect, NodeJS

 Downloads :

  • 36 in Last Month

 Links :

 Examples

¯\_(ツ)_/¯
No examples found for this package

 Readme

Aileron

Build Status

Tiny (<100 SLOC) and minimal URL parsing for NodeJS. Designed as a middleware for connect. Matches URLs to paths, supports wildcards (useful for IDs in REST APIs) and specifies request types for an endpoint (GET, POST, PUT, PATCH, DELETE). I use this extensively when creating API servers.

Typical Use

const connect = require("connect")
const router = require("aileron")
const queryDb = require("magical-db-query-lib")

let app = connect()

app
  .use(router("/team/:teamId", {
    get: (req, res, next, data) => {
      if (data.teamId) {
        res.send(teamDetails(data.teamId))
      } else {
        res.send(teamList())
      }
    },
    put: (req, res, next, data) => {
      updateTeamDetails(data.teamId, (err, result) => {
        if (err) {
          // Add error headers and stuff
          res.send(err)
        } else {
          res.send(result)
        }
      })
    }
  }))

 Comments