Azure function bindings
Bindings provide a way to read/write data from/to different
data services without any additional overhead of managing connection with these
services. Today, we will see that how easy it is to integrate Azure functions
with different services like blob, table storage, queue, cosmos, send grid etc
with help of bindings.
Type of bindings –
- Input binding – As the name implies, the binding is to get data into an Azure function from data service like blob, table storage, cosmos etc.
- Output binding – The binding is to push/add data to different data service from an Azure function like blob, queue, send grid etc.
Demo – We will create
a Todo API with following,
- An azure function with Add/List Api,
- Output binding - Data will be stored in a Table Storage.
- Output binding – We will write the data in a text file and store it in a blob storage.
- Input binding – Read data from table storage to display on UI.
·
I will be using a simple angular page to add/list
todos but it could be a simple html page with some ajax or use any client like
postman to hit the API directly.
I will be using Visual Studio but it is absolutely fine using any IDE like VS Code if want to follow along or refer my previous post getting started with azure functions
- Setup new azure function project with an empty template as shown below,
- Your solution should look like this,
- Add new azure function by following the steps below,
- Add required nuget package by running following command in package manager console,
- Add new class Models.cs and add following,
- Add two endpoints CreateTodo/Todos in API to create and read data.
- Include all necessary namespaces

- CreateTodo endpoint to create a new todo item

- Todos endpoint to get all todos for be displayed

- Now hit the API by using an angular page or java script then It should give you an error like below,
- And this is because we are trying to access an API of different domain from our client App. Now allow cross domain communication by enabling CORS under host in local.settings.json like this,
- You should now have a working azure function with added input/output bindings.









No comments:
Post a Comment