I wrote this post to share my experience implementing middleware pattern in Azure Functions.
Azure Functions is a serverless compute service that enables you to run code _on-demand _without having to explicitly manage infrastructure.
Biggest advantage of serverless computing is that you can focus on building apps and don’t worry about provisioning or maintaining servers. You can write code only for what truly matters to your business.
But in real world applications you have to deal with some common technical concerns outside business logic, like input parsing and validation, output serialization, error handling, and more.
Very often, all this necessary code ends up polluting the pure business logic code in your functions, making the code harder to read and to maintain.
Web frameworks, like Express, Fastify or Hapi, has solved this problem using the middleware pattern. This pattern allows developers to isolate these common technical concerns into “steps” that decorate the main business logic code.
#npm #programming #node #azure-functions #javascript