Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Moleculer validation example

node v6.17.1
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