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. situs toto's avatar situs toto says:

    As a Newbie, I am permanently browsing online for articles that can aid me. Thank you

  2. slot online's avatar slot online says:

    Your place is valueble for me. Thanks!…

  3. I simply could not leave your site prior to suggesting that I extremely enjoyed the standard information a person supply on your visitors? Is going to be back incessantly in order to investigate cross-check new posts

  4. Precisely what I was searching for, appreciate it for posting.

  5. Very well written information. It will be useful to everyone who employess it, including myself. Keep doing what you are doing – can’r wait to read more posts.

  6. Magnificent site. Plenty of useful information here. I’m sending it to some friends ans also sharing in delicious. And of course, thanks for your sweat!

  7. Betogel's avatar Betogel says:

    I’ve learned a few important things via your post. I would also like to convey that there is a situation where you will apply for a loan and do not need a co-signer such as a Federal Student Aid Loan. In case you are getting credit through a regular loan service then you need to be willing to have a cosigner ready to make it easier for you. The lenders are going to base their own decision using a few issues but the greatest will be your credit history. There are some loan providers that will likewise look at your job history and come to a decision based on this but in many instances it will be based on on your rating.

  8. Lunatogel's avatar Lunatogel says:

    Hey! This is my first comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading your blog posts. Can you suggest any other blogs/websites/forums that deal with the same subjects? Appreciate it!

  9. I am glad to be one of several visitors on this outstanding website (:, appreciate it for putting up.

  10. I¦ve been exploring for a little for any high-quality articles or weblog posts on this kind of area . Exploring in Yahoo I ultimately stumbled upon this site. Studying this information So i¦m glad to exhibit that I’ve an incredibly excellent uncanny feeling I discovered exactly what I needed. I such a lot indisputably will make sure to don¦t disregard this site and provides it a look regularly.

  11. Your place is valueble for me. Thanks!…

  12. Would you be keen on exchanging links?

  13. RF Module's avatar RF Module says:

    Hi, Neat post. There is an issue together with your website in web explorer, would test thisK IE nonetheless is the marketplace leader and a big section of folks will omit your great writing due to this problem.

  14. Hi there! I just would like to give an enormous thumbs up for the good information you could have here on this post. I will likely be coming back to your blog for more soon.

  15. Very nice info and right to the point. I am not sure if this is actually the best place to ask but do you folks have any ideea where to hire some professional writers? Thanks 🙂

  16. alexa138's avatar alexa138 says:

    This is a topic close to my heart cheers, where are your contact details though?

  17. you have a great blog here! would you like to make some invite posts on my blog?

  18. Nerve Flow's avatar Nerve Flow says:

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

  19. This really answered my downside, thanks!

  20. Lunatogel's avatar Lunatogel says:

    I have noticed that of all different types of insurance, health care insurance is the most marked by controversy because of the turmoil between the insurance policy company’s necessity to remain adrift and the consumer’s need to have insurance. Insurance companies’ commission rates on health and fitness plans are certainly low, as a result some providers struggle to make a profit. Thanks for the suggestions you discuss through this blog.

  21. I was looking at some of your content on this website and I believe this web site is very instructive! Keep on putting up.

  22. I and my pals happened to be viewing the excellent techniques found on your web page and instantly I got an awful suspicion I never expressed respect to the web site owner for those techniques. The boys had been absolutely passionate to read through all of them and already have quite simply been taking advantage of these things. I appreciate you for genuinely simply helpful and then for picking certain excellent things most people are really wanting to be aware of. My sincere regret for not expressing gratitude to you sooner.

  23. Dagotogel's avatar Dagotogel says:

    Thanks for your article. One other thing is that if you are promoting your property alone, one of the difficulties you need to be aware of upfront is just how to deal with household inspection accounts. As a FSBO vendor, the key to successfully switching your property along with saving money on real estate agent revenue is knowledge. The more you recognize, the softer your home sales effort is going to be. One area where by this is particularly critical is inspection reports.

  24. togel's avatar togel says:

    I’m really loving the theme/design of your website. Do you ever run into any internet browser compatibility problems? A small number of my blog readers have complained about my website not operating correctly in Explorer but looks great in Safari. Do you have any solutions to help fix this problem?

  25. telemedicina's avatar telemedicina says:

    We stumbled over here coming from a different web page and thought I might check things out. I like what I see so now i’m following you. Look forward to going over your web page again.

  26. What’s Happening i’m new to this, I stumbled upon this I’ve found It absolutely useful and it has aided me out loads. I hope to contribute & assist other users like its helped me. Great job.

  27. Regards for helping out, great information.

  28. Hello would you mind letting me know which webhost you’re working with? I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most. Can you recommend a good web hosting provider at a reasonable price? Thanks, I appreciate it!

  29. Thanks for the suggestions about credit repair on this web-site. The things i would tell people would be to give up a mentality they can buy now and shell out later. Being a society many of us tend to do that for many issues. This includes vacation trips, furniture, along with items we’d like. However, you should separate your wants from all the needs. As long as you’re working to fix your credit score make some trade-offs. For example you can shop online to save money or you can click on second hand stores instead of costly department stores regarding clothing.

  30. Honey Trick's avatar Honey Trick says:

    I found your weblog website on google and check a few of your early posts. Proceed to keep up the very good operate. I just further up your RSS feed to my MSN News Reader. In search of ahead to reading extra from you in a while!…

  31. I’ll right away seize your rss as I can’t in finding your email subscription hyperlink or newsletter service. Do you have any? Kindly permit me recognise in order that I may just subscribe. Thanks.

  32. Yesterday, while I was at work, my sister stole my iPad and tested to see if it can survive a forty foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views. I know this is entirely off topic but I had to share it with someone!

  33. Honey Ritual's avatar Honey Ritual says:

    Just a smiling visitant here to share the love (:, btw great design.

  34. Very fantastic info can be found on web site.

  35. This website online is mostly a walk-by way of for all of the data you needed about this and didn’t know who to ask. Glimpse right here, and you’ll undoubtedly discover it.

  36. Honey Trick's avatar Honey Trick says:

    You should take part in a contest for one of the best blogs on the web. I will recommend this site!

  37. I am commenting to let you be aware of what a awesome experience my daughter experienced viewing the blog. She realized such a lot of issues, which included how it is like to possess an excellent teaching spirit to make many people really easily thoroughly grasp specified grueling subject matter. You actually did more than readers’ expectations. Thank you for supplying these warm and friendly, safe, revealing not to mention easy guidance on the topic to Mary.

  38. wede57pro's avatar wede57pro says:

    You have remarked very interesting details! ps decent web site. “Enemies, as well as lovers, come to resemble each other over a period of time.” by Sydney Harris.

  39. Pretty component of content. I simply stumbled upon your website and in accession capital to say that I acquire in fact enjoyed account your weblog posts. Anyway I’ll be subscribing in your augment and even I achievement you get entry to constantly fast.

  40. I have seen plenty of useful points on your website about pcs. However, I have got the view that notebook computers are still not quite powerful more than enough to be a wise decision if you typically do tasks that require plenty of power, for example video enhancing. But for internet surfing, word processing, and many other popular computer work they are perfectly, provided you do not mind small screen size. Thank you sharing your thinking.

  41. Unquestionably believe that which you said. Your favorite justification appeared to be on the web the simplest thing to be aware of. I say to you, I certainly get irked while people consider worries that they plainly don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks

  42. Hello! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Nonetheless, I’m definitely happy I found it and I’ll be book-marking and checking back often!

  43. toto slot's avatar toto slot says:

    Wow that was unusual. I just wrote an very long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say fantastic blog!

  44. cici erina's avatar cici erina says:

    Hi there I am so delighted I found your weblog, I really found you by accident, while I was searching on Bing for something else, Anyways I am here now and would just like to say thanks a lot for a remarkable post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read much more, Please do keep up the fantastic job.

  45. whoah this weblog is fantastic i really like reading your posts. Stay up the good paintings! You already know, a lot of persons are looking around for this info, you could help them greatly.

  46. This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  47. Very nice pattern and excellent written content, practically nothing else we want : D.

  48. Bk8's avatar Bk8 says:

    You should participate in a contest for top-of-the-line blogs on the web. I’ll recommend this website!

  49. Another thing I have noticed is always that for many people, less-than-perfect credit is the reaction to circumstances above their control. For example they may are already saddled with an illness so they have substantial bills for collections. It might be due to a job loss or even the inability to go to work. Sometimes breakup can truly send the funds in a downward direction. Thank you for sharing your ideas on this site.

Comments are closed.