query-router-express

1.3.0 • Public • Published

Query router middleware

A simple Express middleware to route last-mile based on query parameters.

Usage

const express = require('express');
const queryRouter = require('query-router-express');

const router = express.Router();

router.get('/', queryRouter([
	{
		default: true,
		query: {
			criteria: "box"
		}
		handler: async function(req, res) {
			let objs = await getFromDbByBox();

			res.send(objs);
		}
	},
	{
		query: {
			criteria: "near"
		}
		handler: async function(req, res) {
			let objs = await getFromDbNear();

			res.send(objs);
		}
	}
]));

Notes

The middleware requires ES6 async/await as it support async handlers and any error thrown by them will be passed to next.

Readme

Keywords

none

Package Sidebar

Install

npm i query-router-express

Weekly Downloads

10

Version

1.3.0

License

LGPL-3.0

Unpacked Size

3.59 kB

Total Files

3

Last publish

Collaborators

  • uwburn