The schema to use.
The new middleware.
https://www.npmjs.com/package/joi
import assert from 'assert'
import createServer, { IHttpRequest, IHttpResponse, query, schema, validateQuery } from '@egomobile/http-server'
const myQuerySchema = schema.object({
offset: schema.string().strict().regex(/^([0-9]){1,}$/).required(),
limit: joi.string().strict().regex(/^([0-9]){1,}$/).optional()
})
const app = createServer()
app.get('/', [query(), validateQuery(myQuerySchema)], (request, response) => {
assert.strictEqual(typeof request.query!.get('offset'), 'string')
assert.strictEqual(isNaN(request.query!.get('offset')), false)
if (request.query!.get('limit')) {
assert.strictEqual(typeof request.query!.get('limit'), 'string')
assert.strictEqual(isNaN(request.query!.get('limit')), false)
}
})
// ...
Generated using TypeDoc
Creates a middleware, that validates the data of the 'query' property inside the 'request' object with the help of a joi schema.