0.1.1 • Published 9 years ago

koalesce-mw-authentication v0.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

Input Validation Middleware for Koalesce

This module is Koalesce middleware that handles schema validation for url parameters, query strings, and request bodies.

If that sentence doesn't mean anything to you, you can always start here: koalesce-starter. (A working starter app built using angular, koa, node, and mongo.)

Route Fields

The input validation middleware checks for the schema field on a route. The schema object itself is a Joi schema. Refer to the Joi documentation for type specification. A 400 Bad Request is returned if the validation fails.

URL Parameter Example:

routes: {
	example: {
		url: '/:firstParameter/:secondParameter',
		method: 'GET',
		responseContentType: 'json',		// koalesce-mw-response-types
		schema: {
			params: {
				firstParameter: Joi.string(),
				secondParameter: Joi.number()
			}
		},
		handler: function* () {
			console.log('firstParameter', this.params.firstParameter);
			this.status = 200;
			this.body = 'success';
		}
	}
}

Query String Example:

(Request url would contain parameters: /route?parameter1=123&parameter2=456)

routes: {
	example: {
		url: '/route',
		method: 'GET',
		schema: {
			body: {
				parameter1: Joi.number().required(),
				parameter2: Joi.number().required()
			}
		},
		handler: function* () {
			console.log('parameter1', this.request.body.parameter1);
			this.status = 200;
			this.body = 'success';
		}
	}
}

HTTP Request Body Example:

routes: {
	example: {
		url: '/route',
		method: 'POST',
		requestContentType: 'json', 		// koalesce-mw-request-types
		responseContentType: 'json',		// koalesce-mw-response-types
		schema: {
			body: {
				parameter1: Joi.string().max(12).required(),
				parameter2: Joi.number().required()
			}
		},
		handler: function* () {
			console.log('parameter1', this.request.body.parameter1);
			this.status = 200;
			this.body = 'success';
		}
	}
}

Joi options are supported for each type in paramsOptions, queryOptions, and bodyOptions. The Joi

Koalesce Middleware Metadata

There is no metadata for this module.

Configuration Options

There are no configuration options.

0.1.1

9 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

11 years ago