Azure Functions are compute resources that are also referred as serverless.(of course they run on server but we never have to worry about it )
Azure Functions have triggers that define when these functions should be executed. One of the trigger type is HttpTrigger. You can invoke Azure Function by calling an endpoint this endpoint is capable of sending you back a response, how cool it that!
Possibilities with Azure Function and CSOM
- Build Custom API Wrapper on top of SharePoint API — Azure Function can greatly simplify API calls by providing a proxy behavior.
- Easy integration of non-Dot Net Applications — Your Dot Net Application will be Azure Function that can server any client.
- CAS protection to resources — You do not share access to your SharePoint resources, you can build your own CAS model as per your business need as Azure Function.
- And many more…
Create New Function App and function
Login to Azure Portal at https://portal.azure.com and create new Function App instance.
Select Consumption Plan and fill out other details.
Once Function App is created, Create new Function inside Function App. Provide proper name and for simplicity, select HttpTrigger-CSharp as template.
When this function is ready, create a new project.json file. This is the way to tell Azure Function to go and get nuget package which has been added as a dependency.
SharePointPnPCoreOnline is nuget package that we will be using for authenticating with SharePoint Online.
Replace the content of run.csx file with below mentioned code. Replace url, username and password with acutal values and run the code.
using Microsoft.Online.SharePoint.TenantManagement;public static void Run(TimerInfo myTimer, TraceWriter log)
AuthenticationManager authManager = new AuthenticationManager();
ClientContext ctx = authManager
Web web = ctx.Web;
You just called SharePoint CSOM API using Azure Function with just 4 lines of code!
We will see how to build production quality Azure Function using other features like Application settings, Access Code and CORS implementation next.