The standard input and output bindings in Azure Functions are written in a declarative pattern using the function.json. When defining input and output declarative, you do not have the option to change some of the bindings properties like the name or make multiple outputs from one input. An imperative binding can do this for you. In this blog post I’ll show how to use imperative blob bindings.

Imperative binder pattern
The imperative binder uses a pattern where you add the Binder object in the signature of your Run method. In the function you use attributes to bind the output to the binder. You can bind multiple outputs to the binder, and you are able to combine a declarative binding with the imperative binding. In this case the BlobTrigger is defined in function.json. Do not include the output binding in you function.json:

Rename incoming blob
Renaming a blob is basically a two step process. The first step is to copy the content of the blob into a new blob file and the second step is to delete the original blob.
Copy blob
The first step is to copy the blob into a new blob. The new blob name is based on the current datetime in the path. The following code shows how to do this with a binder:

The function.json is the same as in sample 1.

Delete blob
Deleting the original blob can be done declarative and imperative. I’ll show both:

Delete blob declarative
All parameters are declared in the function.json:

This will delete the incoming blob file (the path in the function.json is the same for the input and output).

Delete blob You can also delete the incoming blob imperative using the Binder:

Move/rename blob
Combining the copy and delete give the following code to move/rename the blob:

In the sample code the are multiple (output)actions bind to the Binder.

Make multiple blobs depending on incoming blob
Another use case for the imperative binder can be creating multiple output blobs depending on the incoming blob. You can call the binder multiple time to save all the blobs. As sample I make a new blob for each line in the incoming blob file.

Conclusion
The advanced Binder enables you to make outputs that are based on computations in the function itself. In this sample the blob bindings are used. The same is possible for all other binding types:

Binding Attribute Add reference
DocumentDB
Event Hubs ,
Mobile Apps
Notification Hubs
Service Bus ,
Storage queue ,
Storage blob ,
Storage table ,
Twilio

When making the right choice between an imperative or declarative binding keeps the code clean. This will keep the function code maintainable and future proof.