0.0.1 • Published 9 years ago

skelenode-swagger v0.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Skelenode Swagger

This is a Skelenode component to provide common swagger utilities for standard responses and params. This can be used standalone with any swagger implementation.

Installation

npm install skelenode-swagger

Usage

var swr = require('skelenode-swagger/respond');

// send a standard response from an express or restify route handler
swr.respond({ msg: 'Hello World!' }, res);

The resulting response sent is always in the same form:

{
  success: true|false,
  code: 200|404|ect.,
  result: { ...whatever... }
}

Response Methods

success(result, res, internalCode)

Sends a 200 response with result.

custom(message, res, internalCode, errorCode)

By default, sends a 400 response with the given message. Pass an optional errorCode to override the default.

forbidden(res, internalCode, message)

Sends a 403 response. Pass an optional message to override the default message.

socketNotAllowed(res, internalCode)

Sends a 403 response saying that a socket request is not allowed.

xhrNotAllowed(res, internalCode)

Sends a 403 response saying that an XHR request is not allowed.

notFound(res, internalCode)

Sends a 404 response saying that the given resource was not found.

itemNotFound(name, res, internalCode)

Sends a 404 response saying that the resource named name was not found.

loginRequired(res, internalCode)

Sends a 401 response saying that a login is required.

loginInvalidated(res, internalCode)

Sends a 401 response saying that a login was invalidated.

paramRequired(field, res, internalCode, errorCode)

Sends a 400 response saying that a field is required.

paramInvalid(field, res, internalCode)

Sends a 400 response saying that a field is invalid.

serverError(res, internalCode, errorCode)

By default, sends a 500 response with the details of a server error. Pass an optional errorCode to override the default.

disabled(res, internalCode)

Sends a 500 response saying that feature is disabled.

localhostNotSupported(res, internalCode)

Sends a 500 response saying that localhost is not supported.

notImplemented(res, internalCode)

Sends a 501 response saying that API hasn't been implemented yet.

Contributing

Open a pull request with plenty of well-written instructions on what you are submitting and why you are submitting it