Invoking non-HTTP Azure Functions over HTTP to make development easier

Edit on GitHub

This week, I was presenting at IglooConf (Indexing and searching NuGet org with Azure Functions and Search). During one of the demos, I casually used a feature we shipped with the latest Azure Toolkit for JetBrains Rider: when the Azure Functions host is running on a development machine, Rider lets us trigger functions from the gutter by generating an HTTP request for it.

Trigger Azure Functions from Rider

Chatting with some attendees, not a lot of people are aware this is possible. During development, Azure Functions can be triggered over HTTP, regardless of whether they are using an HTTP trigger or not. For HTTP-triggered functions, there’s of course an HTTP endpoint we can call, but the runtime also provides an endpoint for non-HTTP-triggered functions!

So instead of having to change the schedule expression on a TimerTrigger to see our function get invoked during development, we can invoke it over HTTP, on demand.

POST http://localhost:7071/admin/functions/{functionname}
Content-Type: application/json

{}

This works for most trigger bindings, and we can even provide data to our function. For example with a QueueTrigger, we can pass along the payload of the message it should process (as a string):

POST http://localhost:7071/admin/functions/ExampleQueue
Content-Type: application/json

{
    "input": "{ \"name\": \"Maarten\" }"
}

This will then trigger our function where we can process that payload:

Invoke Azure Function with payload

*Tip: When editing the HTTP fragment in Rider, use Alt+Enter and “edit JSON text fragment” to make escaping the JSON payload easier.

Having the ability to trigger functions that way makes the development flow much smoother! Check the Azure docs for more background info.

Enjoy!

Leave a Comment

avatar

3 responses

  1. Avatar for plebann
    plebann January 8th, 2021

    Maybe you happen to know how to pass multiple parameters? Function I’m trying to post looks like:

    [FunctionName("MyFunction")]
            public async Task Run(
                [ServiceBusTrigger("%triggerName%", Connection = "connectionString")] 
                string myQueueItem, 
                string myField1, 
                string myFIeld2,
                ILogger log)
            {
    

    And I have no idea how to pass parameter other than myQueueItem

  2. Avatar for Maarten Balliauw
    Maarten Balliauw January 11th, 2021

    Not sure about service bus. Looking at https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp, and more specifically the Python example, https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=python, I think you may need to invoke the function with something similar to:

    POST http://localhost:7071/admin/functions/ExampleQueue
    Content-Type: application/json
    
    
    {
    
        "input": "{ \"message_id\": \"guid\", \"body\": \"message contents base64 encoded\", ... }"
    
    }
    

    That input JSON will need the properties and values as defined on https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=javascript#message-metadata

    Again, haven’t tried service bus yet so this will need further investigation :-) But I hope these pointers can help.

  3. Avatar for Tim
    Tim February 19th, 2022

    Thanks, really helped!