Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Latest commit

 

History

History
42 lines (35 loc) · 1.21 KB

request-value-lookup.md

File metadata and controls

42 lines (35 loc) · 1.21 KB

Request Value Lookup

Get a value from one of multiple places in a request. Currently supports:

  • Query
  • Header

Attribute

Name Type Description
Location RequestValueLocation Location to check for value
Name string Priamary key name to look for
Aliases string[] Alternate key names

Example

public static class VersionedHttpTrigger
{
    [FunctionName(nameof(VersionedHttpTrigger))]
    public static async Task<IActionResult> RunAsync(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = "version")]
        HttpRequest req, ILogger log, [
            RequestValue(
            Location = RequestValueLocation.Header | RequestValueLocation.Query,
            Name = "apiVersion",
            Aliases = new[] { "x-api-version" }
        )]
        string version
    )
    {
        if (string.IsNullOrEmpty(version))
        {
            return new BadRequestResult();
        }

        log.LogInformation("Triggered for version {Version}", version);
        return new OkObjectResult(version);
    }
}