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.
Hi my friend! I want to say that this article is amazing, great written and come with almost all significant infos. I?¦d like to see extra posts like this .
Hi, Neat post. There is a problem with your web site in internet explorer, would check this… IE still is the market leader and a big portion of people will miss your fantastic writing due to this problem.
Thanks for the recommendations shared on your own blog. Another thing I would like to express is that losing weight is not supposed to be about going on a dietary fads and trying to get rid of as much weight as possible in a couple of weeks. The most effective way in losing weight is by acquiring it slowly and gradually and obeying some basic suggestions which can help you to make the most from a attempt to lose weight. You may understand and already be following many of these tips, but reinforcing understanding never does any damage.
Thanks – Enjoyed this blog post, is there any way I can receive an update sent in an email every time you write a fresh update?
Hey, I think your blog might be having browser compatibility issues. When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, awesome blog!
Thanks a lot for sharing this with all of us you actually know what you’re talking about! Bookmarked. Please also visit my website =). We could have a link exchange contract between us!
Very interesting details you have noted, thankyou for putting up. “My work is a game, a very serious game.” by M. C. Escher.