New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swagger-router

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-router

An efficient swagger 2 based router with support for multiple APIs. For use in RESTBase.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
346
decreased by-24.12%
Maintainers
1
Weekly downloads
 
Created
Source

Swagger 2 router

Build
Status

Features

  • O(path element) lookup complexity, monomorphic design with simple fast path.
  • Support for prefix-based 'mounting' of swagger specs. Example: Mount the same spec fragments at /en.wikipedia.org/v1/ and /de.wikipedia.org/v1/.
  • Support for capture of fixed path segments. Example: /{domain:en.wikipedia.org}/v1/. This feature is especially useful in prefixes, as it enables the consistent construction of sensible params.
  • Support for static (purely spec-based) listings. Matching requests ending on a slash are passed an array of matching child paths in the spec in the _ls parameter.

Installation

npm install swagger-router

Usage

var Router = require('swagger-router');
var router = new Router();

// The main requirement is that each spec has a 'paths' member with some URL
// patterns
var swaggerSpec = {
    paths: {
        '/': {
            get: {
                hello: 'A listing'
            }
        },
        '/some/{name}': { // This object is returned as 'value'
            get: {
                hello: 'world'
            }
        }
    }
};

router.addSpec(swaggerSpec);

// Perform some lookups
console.log(router.lookup('/some/title'));
/* 
{
    params: {
        name: 'title'
    },
    value: { get: { hello: 'world' } }
}
*/

// Use arrays internally for speed (no escaping / parsing)
router.lookup(['some','path']);

// Trailing slashes set an additional _ls param:
router.lookup(['']); // equivalent: router.lookup('/'); 
/*
{
    params: {
        _ls: ['some'],
        name: 'title'
    },
    value: { get: { hello: 'A listing' } }
}
*/

Keywords

FAQs

Package last updated on 15 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc