Skip to content

daulet/servernet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ServerNET

Azure Functions made easy.

Declare your Azure Function triggers, inputs and outputs in code:

[HttpOutput]
public static async Task<HttpResponseMessage> RunAsync(
    [HttpTrigger(HttpMethod.Post, "users/{username:alpha}")] HttpRequestMessage request,
    string username,
    [Table("User", partitionKey: "{username}", rowKey: "payment")] PaymentInstrument paymentInstrument,
    [Queue("user-queue")] IAsyncCollector<PaymentInstrument> paymentQueue,
    TraceWriter log)
{
    // your code here
}

and then use servernet command line tool to generate Azure Functions release package:

servernet.CLI.exe -a Servernet.Samples.DocumentationSamples.dll -o release/path

that will copy your assembly with its dependencies and generate project.json that is ready to deploy:

{
  "disabled": false,
  "scriptFile": "Servernet.Samples.DocumentationSamples.dll",
  "entryPoint": "Servernet.Samples.DocumentationSamples.ReadmeFunction.RunAsync",
  "bindings": [
    {
      "direction": "out",
      "name": "$return",
      "type": "http"
    },
    {
      "authLevel": "Anonymous",
      "direction": "in",
      "methods": [
        "POST"
      ],
      "name": "request",
      "route": "users/{username:alpha}",
      "type": "httpTrigger"
    },
    {
      "connection": "ReadmeFunction_input_table_paymentInstrument",
      "direction": "in",
      "filter": null,
      "name": "paymentInstrument",
      "partitionKey": "{username}",
      "rowKey": "payment",
      "tableName": "User",
      "take": 0,
      "type": "table"
    },
    {
      "connection": "ReadmeFunction_output_queue_paymentQueue",
      "direction": "out",
      "name": "paymentQueue",
      "queueName": "user-queue",
      "type": "queue"
    }
  ]
}

Using command line tool

Using Azure Functions CLI create a new Function App, and then generate a function from your binary:

servernet.CLI.exe -a assembly.dll -f Namespace.Type.FunctionName -o release/path

Or generate functions for all types decorated with [AzureFunction] in the assembly:

servernet.CLI.exe -a assembly.dll -o release/path

Ready to run it? Follow these steps to configure you Function App as Visual Studio project. If you are going to test it locally be sure to setup connection strings in appsettings.json (you most likely will need to set IsEncrypted: false), but if you are not sure how, just start running the app locally, the console prompt will guide you.

Using [AzureFunction] attribute

Use [AzureFunction] attribute to let command line tool to autodetect functions to generate (see above), or to override parameters like Disabled and Name:

[AzureFunction(Disabled = false, Name = "NameToUseInAzureFunctions")]
public class MyFunctionClass
{
    // currently expecting a single public static method defined
}

Bindings

Code + Events

Azure Functions provides binding of your code to various events/triggers. What ServerNET provides is letting you to focus on your code and generate deployable Azure Functions package, including boilerplate like function.json with trigger/input/output bindings and release layout of the Azure Function. ServerNET also limits you to things that are supported by Azure Functions, e.g. according to Azure Function guidelines when you want to setup a webhook trigger you can't use methods property that you'd normally use for HTTP trigger. ServerNET provides strongly typed parameterization of your triggers, input and output parameters. What can't be enforced in design time (i.e. at compile time) is enforced at generation time (using ServerNET CLI), before you deploy to Azure, which means if there is any problem with your function definition you'll find out as soon as possible.

This library supports all the same trigger, input and output parameters as Azure Functions. Few exceptions are patterns that are bad practice, e.g. out HttpResponseMessage parameter. Pick entry method/function (currently only public static methods are supported) for your logic, decorate it with provided attributes and ServerNET CLI will generate deployable Azure Functions for you:

Kind Trigger Input Output
HTTP
WebHook
Timer
Storage Blob
Storage Queue
Storage Table

HTTP and WebHook bindings

For complete documentation on how to use HTTP and WebHook parameters in Azure Functions see official documentaion. For complete example that uses HTTP request and response see HttpOutputFunction.

HTTP Trigger

Decorate your entry method parameter with [HttpTrigger] attribute (sample). Below is the list of parameter types that can be used with [HttpTrigger] attribute:

  • HttpRequestMessage;
  • Custom type, request body will be deserialized from JSON into your object;

WebHook Trigger

Decorate your entry method parameter with [WebHookTrigger] attribute (sample). Works with the same parameter types as HTTP Trigger.

HTTP Output

Decoreate your entry method (not parameter) with [HttpOutput] attribute (sample). Using out HttpResponseMessage parameter is bad practice, hence only return parameter is supported (including async option with Task<HttpResponseMessage>). Below is the list of parameter types that can be used with [HttpResponse] attribute:

Timer bindings

For complete documentation on how to use Timer parameters in Azure Functions see official documentaion.

Timer Trigger

Decorate your entry method parameter with [TimerTrigger] attribute (sample). Below is the list of parameter types that can be used with [TimerTrigger] attribute:

Blob bindings

For complete documentation on how to use Blob parameters in Azure Functions see official documentaion.

Blob Trigger

Decorate your entry method parameter with [BlobTrigger] attribute (sample). Below is the list of parameter types that can be used with [BlobTrigger] attribute:

Blob Input

Decorate your entry method parameter with [Blob] attribute (sample). Below is the list of parameter types that can be used with [Blob] attribute:

Blob Output

Decorate your entry method out parameter with [Blob] attribute (sample). Below is the list of parameter types that can be used with [Blob] attribute:

Queue bindings

For complete documentation on how to use Queue parameters in Azure Functions see official documentaion.

Queue Trigger

Decorate your entry method parameter with [QueueTrigger] attribute (sample). Below is the list of parameter types that can be used with [QueueTrigger] attribute:

Queue Output

Decorate your entry method out parameter with [Queue] attribute (sample). Below is the list of parameter types that can be used with [Queue] attribute:

  • out T, where T is the type that you want to deserialize as JSON into queue message;
  • out String;
  • out byte[];
  • out CloudQueueMessage;
  • ICollector<T> or IAsyncCollector<T>, where T is one of the supported types;

Table bindings

For complete documentation on how to use Table parameters in Azure Functions see official documentaion.

Table Input

Decorate your entry method parameter with [Table] attribute (sample). Below is the list of parameter types that can be used with [Table] attribute:

  • T, where T is the data type that you want to deserialize the data into;
  • Any type that implements ITableEntity;
  • IQueryable<T>, where T is the data type that you want to deserialize the data into;

Table Output

Decorate your entry method parameter with [Table] attribute (sample). Below is the list of parameter types that can be used with [Table] attribute:

  • out <T>, where T is the data type that you want to serialize the data into;
  • out <T>, where T implements ITableEntity;
  • ICollector<T>, where T is the data type that you want to serialize the data into;
  • IAsyncCollector<T> (async version of ICollector<T>);
  • CloudTable;

About

Azure Functions made easy

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages