Azure Functions API Reference

This document provides a comprehensive reference for the Azure Functions runtime APIs, allowing you to interact with and manage your functions programmatically.

Core Runtime APIs

context Object

The context object is passed to your function at runtime and provides access to essential information and tools.

Properties

Methods

req Object (HTTP Trigger)

Represents the incoming HTTP request.

Properties

res Object (HTTP Trigger)

Represents the outgoing HTTP response.

Properties

Runtime Management APIs

azureFunctions.registerFunction(functionId, handler)

Registers a new function with the runtime.

Parameters:

Example: Registering an HTTP Function


const azureFunctions = require('@azure/functions');

azureFunctions.registerFunction('myHttpTrigger', async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    const name = (req.query.name || req.body.name);
    const responseMessage = name
        ? "Hello, " + name + "!"
        : "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

    context.res = {
        status: 200,
        body: responseMessage
    };
    context.done();
});
            

azureFunctions.invokeFunction(functionId, payload)

Invokes another function within the same function app.

Parameters:

Example: Invoking Another Function


// Inside Function A
module.exports = async function (context, myQueueItem) {
    context.log('Function A received item:', myQueueItem);

    const invocationResult = await azureFunctions.invokeFunction('FunctionB', {
        message: 'Data from Function A',
        originalItem: myQueueItem
    });

    context.log('Result from Function B:', invocationResult);
    context.done();
};
            

Binding SDKs

Refer to the specific SDK documentation for each binding (e.g., Cosmos DB, Storage Queues, Event Hubs) for their respective APIs.

Common Binding Operations

Example: Writing to a Queue Output Binding


// Assuming a queue output binding named 'outputQueue' is configured
module.exports = async function (context) {
    context.log('Queue trigger function processed work item.');
    const messageToSend = {
        id: 123,
        status: 'Processed'
    };
    context.bindings.outputQueue = JSON.stringify(messageToSend);
    context.log('Message sent to output queue.');
    context.done();
};
            

System Functions

Internal functions used by the Azure Functions runtime.

HTTP API Endpoints

While functions are typically invoked via triggers, the runtime exposes certain HTTP endpoints for management and invocation purposes.

POST /admin/functions/{functionName}/invoke

Invokes a specific function. Typically used for testing or manual execution.

Request Body:


{
  "input": { ... } // The input payload for the function
}
        

Response:


{
  "output": { ... }, // The output from the function
  "logs": [ ... ]    // Any logs generated during execution
}
        

Example: Invoking a Function via HTTP

This is a conceptual example. Actual invocation often uses Azure CLI or SDKs.


curl -X POST \
  http://localhost:7071/admin/functions/MyFunctionName/invoke \
  -H 'Content-Type: application/json' \
  -d '{
    "input": {
      "message": "Hello from curl!"
    }
  }'