✨Middy Sparks Joi
Middy Sparks Joi is a middleware for @middy/core
. It validates incoming requests, and if an item does not spark joi we thank it and throw an exception.
Getting Started
First, run yarn add middy-sparks-joi @hapi/joi
or npm i middy-sparks-joi @hapi/joi
in your project directory. Then in your lambda handler:
const middy = // These middlewares are recommendedconst jsonBodyParser = const httpErrorHandler = const Joi = ;const validator = const schema = Joiobject body: Joiobject creditCardNumber: Joi expiryMonth: Joi expiryYear: Joi cvc: Joi nameOnCard: Joi amount: Joi ; const processPayment = { // you don't need to validate the event, the schema you passed to middy-sparks-joi does that for you. const creditCardNumber expiryMonth expiryYear cvc nameOnCard amount = eventbody // do stuff with this data // ... return } moduleexports = handler:
That's it! Middy Sparks Joi protects you from inputs that don't spark joi ✨
Building Joi Schemas
The docs for joi can be found here https://hapi.dev/family/joi/api/