GithubHelp home page GithubHelp logo

azure-functions-model-validator's Introduction

Azure Functions model validator

Easy to use fluent API for validating modesl that arrived via HttpTrigger. Define what should happen when the model is ok. Optionally you can define on-failiure callback. The validator is also in Async version.

Example

public class Request
    {
        [Required]
        public string Name { get; set; }
    }
    
    //...


[FunctionName(nameof(Sync))]
        public static IActionResult Sync(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
            Request req,
            ILogger log)
        {
            return AzureFunctionFluentValidator<Request>.Init
                .OnSuccess(dto => new OkObjectResult($"Hello {dto.Name}"))
                .OnFailure((dto, results) =>
                {
                    results.ForEach(x => log.LogWarning(x.ErrorMessage));
                })
                .ValidateAndReturn(req);
        }
        
          [FunctionName(nameof(Async))]
        public static Task<IActionResult> Async(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
            Request req,
            ILogger log)
        {
            return AzureFunctionFluentAsyncValidator<Request>.Init
                .OnSuccess(async dto =>
                {
                    log.LogInformation($"Waiting for one second");
                    await Task.Delay(1000);
                    return new OkObjectResult($"Hello {dto.Name}");
                })
                .OnFailure(async (dto, results) =>
                {
                    log.LogInformation($"Waiting for one second");
                    await Task.Delay(1000);
                    results.ForEach(x => log.LogWarning(x.ErrorMessage));
                })
                .ValidateAndReturnAsync(req);
        }
        
        

azure-functions-model-validator's People

Contributors

skalahonza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.