In the previous part of this series, we looked at creating our first API. But how do you determine which API is being invoked? This is accomplished with routing.
If you have a Products class your entry (end point) might look like this:
[Function(nameof(Products))] public IActionResult Run(HttpTrigger(AuthorizationLevel.Anonymous, "get", Route="products/{category}/{id: int}")] HttpRequest req, string category, int id) { return new OkObjectResult(new {category, id}); }
Notice the routing property (“products/{category}/{id: int}” — this allows us to customize and restrict the arguments from the desired endpoint. The customer/user can now use the same endpoint for a variety of situations.
You can go further and restrict the type of the parameters, and even provide default values:
Route="products/{category:alpha}/{id: int?}")]
Here we are saying that the category must consist only of standard characters, and the id is optional.
Next up: Options
Note, this material is based on our book Programming APIs with C# and .NET from Packt by Jesse Liberty and Joseph Deluzen.
Usually I do not read post on blogs, however I would like to say that this write-up very forced me to try and do so! Your writing style has been surprised me. Thanks, quite nice post.
I do not even know the way I stopped up here, but I believed this submit used to be good. I do not understand who you are however certainly you are going to a well-known blogger if you aren’t already 😉 Cheers!
Wonderful work! This is the type of info that should be shared around the net. Shame on the search engines for not positioning this post higher! Come on over and visit my site . Thanks =)
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
iuqg15
uraofq