API – Functions Part 3: Routing

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.

Unknown's avatar

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. Liberty is a Senior AI Engineer at the University of Pittsburgh Medical Center, and was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 21 year Microsoft MVP.
This entry was posted in API, APIs, Essentials, Mini-Tutorial and tagged . Bookmark the permalink.

1,212 Responses to API – Functions Part 3: Routing

  1. Excellent post. I was checking constantly this blog and I am impressed! Very useful information specially the last part 🙂 I care for such info a lot. I was looking for this particular information for a long time. Thank you and best of luck.

  2. What i don’t realize is in reality how you are no longer actually much more neatly-liked than you may be right now. You’re so intelligent. You understand therefore significantly with regards to this matter, made me for my part imagine it from numerous various angles. Its like women and men don’t seem to be interested except it’s something to do with Girl gaga! Your individual stuffs excellent. At all times deal with it up!

  3. THABET's avatar THABET says:

    Fantastic beat ! I would like to apprentice at the same time as you amend your site, how could i subscribe for a weblog site? The account helped me a applicable deal. I had been a little bit acquainted of this your broadcast provided shiny transparent idea

  4. olxtoto's avatar olxtoto says:

    magnificent points altogether, you simply gained a brand new reader. What would you suggest in regards to your post that you made a few days ago? Any positive?

  5. You are my intake, I own few web logs and rarely run out from to post .

  6. Wow! This can be one particular of the most beneficial blogs We have ever arrive across on this subject. Basically Wonderful. I’m also an expert in this topic therefore I can understand your effort.

  7. naturally like your web site however you need to check the spelling on quite a few of your posts. Many of them are rife with spelling problems and I find it very troublesome to tell the truth on the other hand I’ll surely come back again.

  8. Bk8's avatar Bk8 says:

    Hi, I think your blog might be having browser compatibility issues. When I look at your blog 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, great blog!

  9. Hi my friend! I wish to say that this article is awesome, nice written and include approximately all significant infos. I’d like to see more posts like this.

  10. rtp mpo800's avatar rtp mpo800 says:

    I was looking through some of your blog posts on this website and I conceive this internet site is rattling instructive! Continue putting up.

  11. kelinciapi's avatar kelinciapi says:

    F*ckin’ amazing issues here. I am very happy to peer your post. Thank you so much and i’m looking forward to touch you. Will you kindly drop me a e-mail?

  12. hello!,I like your writing very a lot! share we keep up a correspondence more about your article on AOL? I need a specialist in this space to resolve my problem. May be that’s you! Taking a look ahead to peer you.

  13. I am glad to be a visitant of this complete web blog! , appreciate it for this rare information! .

  14. slvip's avatar slvip says:

    Howdy! I know this is kind of off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having trouble finding one? Thanks a lot!

  15. You made some nice points there. I did a search on the subject matter and found most guys will approve with your site.

  16. slot pucuk's avatar slot pucuk says:

    I have recently started a web site, the information you offer on this web site has helped me tremendously. Thank you for all of your time & work. “Money is power, freedom, a cushion, the root of al evil, the sum of all blessings.” by Carl Sandburg.

  17. ughoki login's avatar ughoki login says:

    Good write-up, I am normal visitor of one’s web site, maintain up the nice operate, and It’s going to be a regular visitor for a lengthy time.

  18. I think you have observed some very interesting points, thanks for the post.

  19. toto togel's avatar toto togel says:

    I have recently started a site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. “A physicist is an atom’s way of knowing about atoms.” by George Wald.

  20. I conceive you have mentioned some very interesting points, regards for the post.

  21. This web site is really a walk-through for all of the info you wanted about this and didn’t know who to ask. Glimpse here, and you’ll definitely discover it.

  22. gestor iptv's avatar gestor iptv says:

    I think this website holds some rattling fantastic information for everyone. “Drunkenness is temporary suicide.” by Bertrand Russell.

  23. I am not sure where you are getting your info, but good topic. I needs to spend some time learning much more or understanding more. Thanks for great info I was looking for this info for my mission.

  24. I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

  25. I really enjoy looking through on this site, it has superb articles.

  26. Rateio's avatar Rateio says:

    I visited a lot of website but I think this one contains something extra in it in it

  27. Prostavive's avatar Prostavive says:

    Your home is valueble for me. Thanks!…

  28. 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 .

  29. dewalive's avatar dewalive says:

    I think other site proprietors should take this web site as an model, very clean and fantastic user friendly style and design, as well as the content. You’re an expert in this topic!

  30. filma24's avatar filma24 says:

    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.

  31. atm4d's avatar atm4d says:

    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.

  32. 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?

  33. toto macau's avatar toto macau says:

    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!

  34. slot online's avatar slot online says:

    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!

  35. Very interesting details you have noted, thankyou for putting up. “My work is a game, a very serious game.” by M. C. Escher.

  36. atm4d's avatar atm4d says:

    Heya! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no back up. Do you have any solutions to stop hackers?

  37. 1xmpo login's avatar 1xmpo login says:

    I love your blog.. very nice colors & theme. Did you create this website yourself? Plz reply back as I’m looking to create my own blog and would like to know wheere u got this from. thanks

  38. Good write-up, I am normal visitor of one¦s site, maintain up the nice operate, and It’s going to be a regular visitor for a long time.

  39. Definitely, what a fantastic blog and illuminating posts, I surely will bookmark your website.Have an awsome day!

  40. I in addition to my friends were actually reading through the good information located on your web blog while at once came up with an awful feeling I never thanked the web site owner for those tips. Those men came as a consequence very interested to read through all of them and already have absolutely been loving those things. I appreciate you for turning out to be well considerate as well as for figuring out this form of great information most people are really desirous to understand about. My very own sincere apologies for not expressing gratitude to earlier.

  41. I always was interested in this topic and stock still am, thankyou for posting.

  42. I do enjoy the way you have presented this particular concern plus it really does give me personally some fodder for thought. On the other hand, through what I have witnessed, I only wish as other remarks stack on that men and women keep on issue and in no way get started on a tirade regarding some other news du jour. Anyway, thank you for this exceptional piece and whilst I do not agree with the idea in totality, I respect the standpoint.

  43. Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to find out if its a problem on my end or if it’s the blog. Any feed-back would be greatly appreciated.

  44. Assessors's avatar Assessors says:

    Hey there this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get guidance from someone with experience. Any help would be enormously appreciated!

  45. Thanks for some other wonderful post. The place else may anyone get that kind of information in such a perfect approach of writing? I’ve a presentation next week, and I’m on the look for such information.

  46. You are my intake, I own few blogs and often run out from to brand : (.

  47. I like what you guys are up also. Such smart work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my web site :).

  48. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…

Comments are closed.