Search code examples
c#asp.net-coreswaggerhttp-headers

Add Multiple Header Values in Swagger


I know how to add one header value in Swagger, here's the code:

[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID)
{
   //...
}

But what if I would like to add additional header values, such as "TenantID", "UserID", etc.

How would the syntax look like?


Solution

  • Just add more parameters, and include the FromHeader attribute on each parameter you want to match:

    [HttpGet]
    [Route("api/{bookID}")]
    public async Task<IActionResult> GetBooksByID(
        string bookID,
        [FromHeader(Name = "Correlation-ID")] string correlationID,
        [FromHeader(Name = "Tenant-ID")] string tenantID,
        [FromHeader(Name = "User-ID")] string userID)
    {
       //...
    }