Moleculer validation example

node v6.12.2
version: 1.0.0
endpointsharetweet
let { ServiceBroker } = require("moleculer"); let broker = new ServiceBroker({ validation: true // Default is true }); broker.createService({ name: "say", actions: { hello: { // Parameters definitions to validator params: { name: { type: "string", min: 2 } }, handler(ctx) { return "Hello " + ctx.params.name; } } } }); broker.call("say.hello").then(console.log).catch(err => console.error(err.data)); broker.call("say.hello", { name: 123 }).then(console.log).catch(err => console.error(err.data)); broker.call("say.hello", { name: "Walter" }).then(console.log).catch(err => console.error(err.data));
Loading…

no comments

    sign in to comment