beanify-url
v3.0.6
Published
beanify-plugin beanify-url beanify micro-service
Downloads
8
Maintainers
Readme
beanify-url
Tool for using url
as parameter delivery method
npm i beanify-url --save
with yarn
yarn add beanify-url
Usage
const Beanify = require('beanify')
const Url = require('beanify-url')
const beanify = Beanify({})
beanify
.register(Url)
.route({
url: 'math.:action',
handler (req, rep) {
rep.send(req.params) // { action: 'sub' } { action: 'add' }
}
})
.ready(async e => {
console.log(e && e.message)
beanify.print()
await beanify.inject({
url: 'math.sub'
})
await beanify.inject({
url: 'math.add'
})
})
Request Decorators
params
: get the parameters passed throughurl
Using beanify-ajv
Usage
const Beanify = require('beanify')
const Url = require('beanify-url')
const ajv = require('beanify-ajv')
const beanify = Beanify({})
beanify
.register(ajv, {
ajv: {
useDefaults: true,
coerceTypes: true
}
})
.register(Url)
.route({
url: 'math.:action',
schema: {
params: {
type: 'object',
properties: {
action: {
type: 'number'
}
}
}
},
handler (req, rep) {
rep.send(req.params) // { action: 123 }
}
})
.ready(async e => {
console.log(e && e.message)
beanify.print()
await beanify.inject({
url: 'math.123'
})
})
Route Decorators
schema
: optionsparams
: to checkreq.params
field.check here