# API request body validation

**URL:** <https://forum.serverless.com/t/api-request-body-validation/1187>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [January 28, 2017, 8:26pm UTC](https://forum.serverless.com/t/api-request-body-validation/1187 "2017-01-28T20:26:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![endymion](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/endymion/32/178_2.png) [@endymion](https://forum.serverless.com/u/endymion)\
**Post date:** [January 28, 2017, 8:26pm UTC](https://forum.serverless.com/t/api-request-body-validation/1187/1 "2017-01-28T20:26:33Z")

</div>

Hi guys,  
I’m wondering how can I validate request body fields (you know username, email, etc.) using node.js.  
Currently I’m using dynogels as database odm and using joi for field validation but I don’t want to relay in the last step of the process to validate the data.

Which is the best form in order to validate incoming body requests and fail on lambda integration?  
Any useful libraries?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [January 29, 2017, 5:14am UTC](https://forum.serverless.com/t/api-request-body-validation/1187/2 "2017-01-29T05:14:29Z")

</div>

I’ve been using [validator.ts](https://www.npmjs.com/package/validator.ts) lately but that only helps if you’re using TypeScript. It looks promising but I really need to clean up the default error messages.

---

<div class="post-metadata">

**Author:** ![endymion](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/endymion/32/178_2.png) [@endymion](https://forum.serverless.com/u/endymion)\
**Post date:** [January 30, 2017, 11:17pm UTC](https://forum.serverless.com/t/api-request-body-validation/1187/3 "2017-01-30T23:17:46Z")

</div>

Thanks @buggy, I’m not using TypeScript but as I see I should use Joi.js by creating ‘request body’ schema payloads. Currently I don’t mind the error messages because I’m using lambda integration and our development schedule is very tight. I hope to get rid of that one day 🙂
