npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sagr

v0.0.1

Published

Simple router for AWS Lambdas receiving AWS API-Gateway events.

Downloads

1

Readme

Simple-Api-Gateway-Router

An ES6 rewrite of the Alpr package.

This package aims to make request routing in a lambda function simple and effective. Used in pair with the serverless framework you can create a resource API with a single handler.

Content

Usage

Add this Simple-Api-Gateway-Router to your project.

$> npm install --save sagr  
  
or  
  
$> yarn add sagr  

In your handler:

const Router = require('sagr');

function Handler(event, context, callback) {
	const router = new Router({ event, context, callback });

	router.route({
		method: 'POST',
		path: '/api/test',
		handler: (req, res) => {
			res({
				statusCode: 200,
				body: {
					message: 'hello world !'
				},
				headers: {
					'x-header': 'hello',
				},
			}),
		}
	});
	
	router.route({
		// You can provide multiple methods
		method: ['POST', 'GET', 'PUT'],
		// And different paths
		path: ['/api/test', '/api/test/{variable}'],
		handler: (req, res) => {
			res({
				statusCode: 200,
				body: {
					message: 'hello world !'
				},
				headers: {
					'x-header': 'hello',
				},
			}),
		}
	});

	// If no route has been matched, the router will answer with a common 404 response.
	router.done();
}

module.exports = {
	handler
};

Routes

| Key | Type | Value |---|---|--- | method | string/Array | The http method the route should match for. More than one can be specified | path | string/Array | This should match the value of the route specified in API gateway including path parameter names | handler | Function | The handler function for the given route. Should take two parameters of request and response.

Handler

The handler is need to match the route specified and process the answer. it takes a request parameter which help you reach the request information needed in your computing, and a response callback which answer back with a formatted response to the API-Gateway.

Request

| Key | Type | Value |---|---|--- | request.getContext | Function | Return the whole lambda context object. | request.getStage | Function | Return the API Gateway stage variables. | request.getQuery | Function | Return the query string parameters. | request.getBody | Function | Return the JSON parsed body. | request.getRaw | Function | Return the raw event object. | request.getPath | Function | Return the request path parameters. | request.getHeaders | Function | Return the request headers.

Response

The response callback send back a formatted response to the API-Gateway.

| Key | Type | Value | Default |---|---|---|--- | params | Object | Parameters object | {} | params.statusCode | Integer | The HTTP status code | 200 | params.headers | Object | Any headers to be returned in the response. | {} | params.body | Mixed | Your response body, whatever is specified will be JSON.stringify'd. If body is not set the body will be defined as the params object. | JSON.stringify(params) | params.isBase64Encoded | Boolean | This is usually used for serving binary data from an API. | false

Here is the recommended way to call the response method.

response({
    statusCode: 200,
    headers: { "x-your-header": "header value" },
    body: { "response-object-key": "data" },
});

And response('hello world') would work out as:

{
    statusCode: 200,
    headers: {},
    body: "hello world"
}

Credits to aceew for it's router.