Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sans-server-swagger

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sans-server-swagger

Sans-server middleware that uses swagger documents to validate requests and responses and to produce mocks.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

node-byuapi-framework

A serverless framework that uses Swagger documents to produce web service schemas. Easy to integrate into unit tests, servers, AWS lambdas, etc.

Basic Usage

Example

const byuApi = require('node-byuapi-framework');

// create an API instance
const api = byuApi({
    controllers: './controllers',
    development: true,
    swagger: './swagger.json'
});

// make a request against the API
api.request({ method: 'GET', path: '/v1/path/to/call' })
    .then(function(res) {
        console.log(res.statusCode);
        console.log(res.body);
    });

Configuration

The API instance is generated using a configuration with the following properties:

  • controllers - [REQUIRED] The directory path to JavaScript files that contain the methods to execute to fulfill web service requests.

  • development - [OPTIONAL] If true then mocks will be used automatically when a controller does not exist and not all controllers must exist, otherwise all controllers must exist. Defaults to false.

  • ignoreBasePath - [OPTIONAL] If true then the swagger base path will not be used in the routes. Defaults to false.

  • sansServer - [OPTIONAL] A configuration to pass to sans-server. Defaults to {}.

  • sansServerRouter - [OPTIONAL] A configuration to pass to the sans-server-router instance that this middleware employs. Defaults to: { paramFormat: 'handlebar' }.

  • swagger - [REQUIRED] The swagger file that defines the services. This can be either a json or a yaml file.

As Middleware

This middleware that this framework uses to route requests through swagger can also be used as middleware.

const byuApi = require('node-byuapi-framework');
const Server = require('sans-server');

const server = Server();

// add middleware before the byuapi framework
server.use(function(req, res, next) {
    // Do something
    next();
});

// add the byuapi framework middleware
const middlewareConfig = {
    controllers: './controllers',
    development: true,
    sansServerRouter: { passThrough: true },    // tell the router employed here to pass unresolved requests through
    swagger: './swagger.json'
};
server.use(byuApi.midddleware(middlewareConfig));

// this middleware gets requests that have not been resolved yet
server.use(function(req, res, next) {
    res.status(404);
    res.send('Could not find what you were looking for.');
});

// make a request against the API
server.request({ method: 'GET', path: '/some/path' })
    .then(function(res) {
        console.log(res.statusCode);
        console.log(res.body);
    });

Keywords

FAQs

Package last updated on 02 Mar 2017

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