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 🙏

© 2024 – Pkg Stats / Ryan Hefner

swole

v2.0.0

Published

HTTP request router for Swagger/OpenAPI

Downloads

31

Readme

swole Build Status

HTTP request router for Swagger/OpenAPI

Swole is a configuration oriented router that glues your Swagger API definition to request handlers without any framework dependencies. Swole uses your API definition to handle parsing/validation of user inputs and can even validate responses.

Install

$ npm install --save swole

Usage

var Swole = require('swole')
var api = {
  swagger: '2.0',
  info: {
    title: 'API'
  },
  paths: {
    '/beep': {
      get: {
        'x-handler': 'beep',
        responses: {
          200: {
            schema: {
              type: 'string',
              enum: ['boop']
            }
          }
        }
      }
    }
  }
}

var swole = Swole(api, {
  handlers: {
    beep: (req, res, callback) => res.end('boop', callback)
  }  
})

server.on('request', function (req, res) {
  swole(req, res, function (err) {
    if (err) {
      res.statusCode = err.statusCode || 500
      return res.end(JSON.stringify(err))
    }
  })
})

And make a request:

GET /beep
#=> 200 boop

API

Swole(swagger, options) -> function

Creates a new Swole API handler using a Swagger definition and options.

Returns a req, res, callback middleware function. Swole will append the matched path and operation values as req.swole as a {path, operation} object.

swagger

Required
Type: object

A Swagger API definition object.

options
handlers

Required
Type: object{function}

An object containing req, res, callback handler functions that match to x-handler keys in your operations objects.

hooks

Type: array[function]

An array of req, res, callback handler functions that will be called in series before executing handlers. These functions are run after the parameters for the request have been parsed and validated.

accepts

Type: array[string]
Default: ['json']

A list of body parsers to use for parsing request streams.

strict

Type: boolean
Default: false

In strict mode, swole will validate outgoing payloads in addition to incoming data. This is slow and expensive and should only be used for development/debugging.

lowercase

Type: boolean
Default: true

By default, Swole coerces paths into lowercase for simplicity. In practice, this makes everything but your path parameters case insensitive. To make routing case sensitive, set this to false.

License

MIT © Ben Drucker