how to specify tc2/users/Groups/{id=EMPTY}/?{startIndex=EMPTY&count=EMPTY} operation in azure function route ex: Groups?startIndex={startIndex}&count={count}

Guduru, Sravan Kumar 21 Reputation points
2022-03-03T02:37:15.377+00:00

in my case the url's will be in three formats . url is expected to be in any of the three (below) formats. That is where i am confused

  1. Groups
  2. Groups/id
  3. Groups?startIndex={startIndex}&count={count}

can you help me how to do this ?

1

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,355 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,416 Reputation points
    2022-03-07T07:12:32.247+00:00

    @Guduru, Sravan Kumar Thanks for reaching out. You can only define string value as the Route property is of type string.
    As per your requirement, you can define the Route as below and to get the query parameter you can leverage HttpRequest object Query parameter. For more details on the route parameter and query string please refer to this document.
    Route = "tc2/users/Groups/{id:int?}"

    180440-image.png

    I have used the below C# code for testing purposes.

    public static async Task<IActionResult> Run(  
                [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "tc2/users/Groups/{id:int?}")] HttpRequest req, int? id,  
                ILogger log)  
            {  
                log.LogInformation("C# HTTP trigger function processed a request.");  
      
                int startIndex, count;  
      
                if (!String.IsNullOrEmpty(req.Query["startIndex"]))  
                    startIndex = int.Parse(req.Query["startIndex"]);  
      
                if (!String.IsNullOrEmpty(req.Query["count"]))  
                    count = int.Parse(req.Query["count"]);  
      
                return new OkObjectResult("Ok");  
            }  
    

    Note: The above is only for reference and please update it as per your business needs and handle the exception while converting the query parameter

    0 comments No comments

0 additional answers

Sort by: Most helpful