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

HttpQueryAttribute

Jussi Saarivirta edited this page Jan 26, 2019 · 2 revisions

HttpQueryAttribute

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

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

Example:

GET http://localhost:7071/api/query-basics?someString=hello
  &anotherString=world
  &myObject={"x":1}
  &numberArray=1&numberArray=2
  &stringList=hello&stringList=world
[FunctionName("QueryParametersDemo1")]
public static async Task<IActionResult> QueryParametersDemo1(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "query-basics")] HttpRequest req,
    [HttpQuery(Required = true)]HttpParam<string> someString,
    [HttpQuery(Name = "anotherString")]HttpParam<string> yetAnother,
    [HttpQuery]HttpParam<MyObject> myObject,
    [HttpQuery]HttpParam<long[]> numberArray,
    [HttpQuery]HttpParam<List<string>> stringList,
    ILogger log)
{
    log.LogInformation($"someString: {someString}");
    log.LogInformation($"anotherString: {yetAnother}");
    log.LogInformation($"myObject: {JsonConvert.SerializeObject(myObject.Value)}");
    log.LogInformation($"numberArray: {JsonConvert.SerializeObject(numberArray.Value)}");
    log.LogInformation($"stringList: {JsonConvert.SerializeObject(stringList.Value)}");
    return new OkObjectResult("ok");
}

Clone this wiki locally