Azure Functions Beginner

HTTP-triggered functions

HTTP-triggered functions turn a method into a small web endpoint. With ASP.NET Core integration you use the familiar HttpRequest, model binding and IActionResult, plus routes and authorization levels from the trigger attribute.

An HTTP function request
  1. StartClient calls URLGET /api/orders/42 with a key or token.
  2. Step 2Front end checks keyWrong or missing function key returns 401.
  3. Step 3Route binds values{id:int} becomes the id parameter.
  4. Step 4Function runsCalls the injected service.
  5. EndResult returnedIActionResult becomes the HTTP response.

Responses must be sent within about 230 seconds.

Routes and methods

By default the URL is /api/<FunctionName>. Set Route to get REST-style URLs with parameters, which bind to method parameters by name.

C#
public class OrdersApi(IOrderStore store)
{
    [Function("GetOrder")]
    public async Task<IActionResult> Get(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = "orders/{id:int}")] HttpRequest req,
        int id)
    {
        var order = await store.FindAsync(id);
        return order is null ? new NotFoundResult() : new OkObjectResult(order);
    }

    [Function("CreateOrder")]
    public async Task<IActionResult> Create(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = "orders")] HttpRequest req,
        [FromBody] NewOrder input)
    {
        var id = await store.AddAsync(input);
        return new CreatedResult($"/api/orders/{id}", new { id });
    }
}

Authorization levels

  • Anonymous: anyone can call it.
  • Function: the caller must send a function key (x-functions-key header or ?code=). Good for webhooks and server-to-server calls.
  • Admin: needs the master key; avoid for normal endpoints.
  • Keys are shared secrets, not user logins. For user-facing APIs add Microsoft Entra ID authentication or put API Management in front.

Limits to know

An HTTP request must get its response within about 230 seconds, because of the Azure load balancer in front of the app, whatever functionTimeout says. For longer work, accept the request, queue the job and return 202 Accepted with a status URL.

Change the /api prefix with extensions.http.routePrefix in host.json if you need clean URLs.

Good habits

  • Validate input and return 400 with a clear message for bad requests.
  • Inject services and keep the function thin; it only translates HTTP to a call into your code.
  • Return the right status codes: 200, 201 with a location, 202 for queued work, 404, 409.

Interview question

How do you secure an HTTP-triggered Azure Function?

The trigger's authorization level gives a basic key check: Function level needs a function key in a header or query string. Keys are shared secrets, so I use them only for webhooks and server-to-server calls. For user-facing APIs I enable Microsoft Entra ID authentication on the app or put API Management in front, and check roles or claims in code.

Your progress is saved only in this browser.

Want the full details? Read the official Microsoft documentation for this topic.