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

HttpHeaderAttribute

Jussi Saarivirta edited this page Jan 26, 2019 · 1 revision

HttpQueryAttribute

Annotation for a HttpParam indicating that its value comes from the HttpRequest headers.

Contains the Name (indicates the header name) and Required (if true, throws exception when header not provided) properties.

Default deserialization can convert header values into objects, assuming that the provided value is valid JSON.

Example:

GET http://localhost:7071/api/header-basics
x-my-header: hello world
x-my-json-header: {"name": "John"}    
[FunctionName("HeaderParametersDemo1")]
public static async Task<IActionResult> HeaderParametersDemo1(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "header-basics")] HttpRequest req,
    [HttpHeader(Name = "x-my-header")]HttpParam<string> myBasicHeader,
    [HttpHeader(Name = "x-my-json-header")]HttpParam<MyObject> myJsonHeader,
    ILogger log)
{
    log.LogInformation($"x-my-header: {myBasicHeader}");
    log.LogInformation($"x-my-json-header: {JsonConvert.SerializeObject(myJsonHeader.Value)}");
    return new OkObjectResult("see the log");
}

Clone this wiki locally