4

I have just started to look at Azure Functions and one of my biggest concerns currently is validation.

I have only really looked at the CRUD operations so far, but there doesn't look like a way to easily validate data coming from the request or into the storage.

I have found this poco-validation and thought it might be useful.

I know this is kind of and open ended question but I'd be interested to see what others was doing for validation.

Andrew Davis
  • 460
  • 3
  • 17
  • Can you clarify more about your requirement? If you'd like to validate the nonnull data and data format (phone number and email etc), you can try to use regular expressions to validate your data based on your requirement. – Fei Han Sep 12 '17 at 02:15
  • Well I have started be adding model binding and validation attributes, but that seems to be a lot of code for what it does. The other way is to get the object out of the request in the way that's in the template then validate that before assigning it to a variable. This is ok, but doesn't seem to be very DRY. – Andrew Davis Sep 12 '17 at 07:06
  • Here's a post that provides examples using the FluentValidation library: https://www.tomfaltesek.com/azure-functions-input-validation/ – Tom Faltesek Jun 27 '19 at 21:19
  • 1
    @TomFaltesek Nice post! – Daniel Lidström Oct 17 '19 at 12:21

1 Answers1

5

We recently added Function Filters to the underlying WebJobs SDK but that feature isn't fully exposed yet in Azure Functions (see issue here). Related to this, we're also considering support for validation annotations to be applied to your POCO types (issue here).

Until the above issues are addressed, we realize the story for validation isn't great. The recommended approach is to perform required validation in your function code calling out to shared validation helpers/code as needed.

mathewc
  • 13,312
  • 2
  • 45
  • 53