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.






































horse gelatin for men
When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove me from that service? Cheers!
I do agree with all of the concepts you have presented for your post. They’re really convincing and can certainly work. Nonetheless, the posts are too brief for beginners. May just you please prolong them a bit from subsequent time? Thanks for the post.
Great breakdown of routing in APIs, Jesse. I’ve been working on a small project recently and was struggling with how to structure my endpoints cleanly—your examples really clarified the concept for me. Do you have any tips for handling nested routes without making the code too messy?
hello there and thank you for your information – I have definitely picked up something new from right here. I did however expertise some technical issues using this web site, as I experienced to reload the web site many times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will often affect your placement in google and can damage your high-quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my e-mail and could look out for a lot more of your respective interesting content. Make sure you update this again soon..
ket web
https://pharmmex.today/# farmacia online usa
Reliable info. Cheers.
Wein Plaza – https://weinplaza.com/
https://swtop.online/# Svenska Pharma
aceton apotek: acne plГҐster apotek – linsvГ¤tska apotek
Great breakdown of routing in APIs, Jesse. I’ve been building a small project with Express and your explanation of how route parameters and query strings differ really cleared up some confusion I had about structuring endpoints. Do you have any tips for handling nested routes cleanly without making the code too messy?
Really excellent visual appeal on this website , I’d value it 10 10.