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

    Greetings! Very helpful advice on this article! It is the little changes that make the biggest changes. Thanks a lot for sharing!

  2. malware's avatar malware says:

    Excellent site. A lot of helpful info here. I am sending it to some friends ans also sharing in delicious. And obviously, thank you for your effort!

  3. malware's avatar malware says:

    you’ve got an ideal weblog here! would you prefer to make some invite posts on my weblog?

  4. bank soal's avatar bank soal says:

    I will immediately clutch your rss as I can not in finding your e-mail subscription hyperlink or newsletter service. Do you’ve any? Kindly permit me realize so that I may just subscribe. Thanks.

  5. glpro's avatar glpro says:

    **glpro**

    glpro is a natural dietary supplement designed to promote balanced blood sugar levels and curb sugar cravings.

  6. I’m extremely inspired with your writing talents as well as with the layout for your blog. Is this a paid theme or did you modify it yourself? Either way stay up the nice high quality writing, it is rare to peer a great weblog like this one today..

  7. nextogel's avatar nextogel says:

    Everything is very open and very clear explanation of issues. was truly information. Your website is very useful. Thanks for sharing.

  8. malware's avatar malware says:

    Merely wanna remark on few general things, The website design and style is perfect, the content material is real superb. “In business school classrooms they construct wonderful models of a nonworld.” by Peter Drucker.

  9. nextogel's avatar nextogel says:

    I?¦ll right away grab your rss as I can not find your e-mail subscription link or newsletter service. Do you’ve any? Kindly permit me know so that I could subscribe. Thanks.

  10. nonton film's avatar nonton film says:

    I found your weblog web site on google and verify a number of of your early posts. Proceed to maintain up the excellent operate. I simply further up your RSS feed to my MSN Information Reader. In search of forward to reading extra from you in a while!…

  11. Malware's avatar Malware says:

    I like what you guys are up too. Such clever work and reporting! Carry on the superb works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website :).

  12. nextogel's avatar nextogel says:

    What i do not realize is in reality how you are no longer actually much more neatly-favored than you may be right now. You are very intelligent. You know therefore considerably in terms of this matter, produced me for my part believe it from a lot of varied angles. Its like men and women are not fascinated unless it is something to do with Lady gaga! Your personal stuffs nice. At all times take care of it up!

  13. kopitogel's avatar kopitogel says:

    Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. It extremely helps make reading your blog significantly easier.

  14. Malware's avatar Malware says:

    Hi there! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the outstanding work!

  15. As a Newbie, I am always exploring online for articles that can aid me. Thank you

  16. kopitogel's avatar kopitogel says:

    Good post. I study something more challenging on totally different blogs everyday. It will at all times be stimulating to read content material from different writers and apply just a little something from their store. I’d prefer to make use of some with the content on my weblog whether or not you don’t mind. Natually I’ll offer you a link in your net blog. Thanks for sharing.

  17. nervital's avatar nervital says:

    I truly enjoy looking at on this web site, it contains great content. “Violence commands both literature and life, and violence is always crude and distorted.” by Ellen Glasgow.

  18. kopitogel's avatar kopitogel says:

    I am extremely impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a nice blog like this one these days..

  19. Please let me know if you’re looking for a author for your weblog. You have some really great articles and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine. Please shoot me an email if interested. Cheers!

  20. 4d's avatar 4d says:

    Saved as a favorite, I really like your blog!

  21. I was looking through some of your articles on this internet site and I conceive this site is rattling informative ! Keep putting up.

  22. PH22's avatar PH22 says:

    Loving the information on this internet site, you have done outstanding job on the blog posts.

  23. Some times its a pain in the ass to read what blog owners wrote but this internet site is rattling user pleasant! .

  24. Normally I do not read article on blogs, but I would like to say that this write-up very pressured me to try and do it! Your writing style has been surprised me. Thank you, very great post.

  25. raja botak's avatar raja botak says:

    Attractive portion of content. I simply stumbled upon your blog and in accession capital to claim that I acquire in fact loved account your weblog posts. Any way I’ll be subscribing to your augment and even I achievement you get admission to persistently quickly.

  26. My spouse and I absolutely love your blog and find almost all of your post’s to be exactly what I’m looking for. Do you offer guest writers to write content for you personally? I wouldn’t mind publishing a post or elaborating on a number of the subjects you write in relation to here. Again, awesome web site!

  27. One thing is that when you’re searching for a education loan you may find that you’ll need a co-signer. There are many conditions where this is true because you will find that you do not employ a past credit history so the bank will require that you have someone cosign the money for you. Good post.

  28. alexaslot138's avatar alexaslot138 says:

    fantastic post, very informative. I wonder why the opposite specialists of this sector do not notice this. You should continue your writing. I am sure, you’ve a huge readers’ base already!

  29. toto's avatar toto says:

    Enjoyed looking at this, very good stuff, thanks. “We swallow greedily any lie that flatters us, but we sip little by little at a truth we find bitter.” by Denis Diderot.

  30. As soon as I detected this web site I went on reddit to share some of the love with them.

  31. wbo777's avatar wbo777 says:

    I am constantly thought about this, thankyou for putting up.

  32. toto macau's avatar toto macau says:

    I like this web site very much, Its a real nice place to read and incur information.

  33. wbo777's avatar wbo777 says:

    Perfect piece of work you have done, this web site is really cool with fantastic info .

  34. slot terbaru's avatar slot terbaru says:

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

  35. I like the helpful info you provide in your articles. I will bookmark your blog and check again here regularly. I’m quite sure I’ll learn many new stuff right here! Good luck for the next!

  36. Thanks for sharing superb informations. Your site is so cool. I’m impressed by the details that you have on this blog. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched all over the place and simply could not come across. What a perfect website.

  37. toto303's avatar toto303 says:

    The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

  38. toto togel's avatar toto togel says:

    Utterly indited content, thanks for information .

  39. This website can be a walk-by for all the information you wished about this and didn’t know who to ask. Glimpse right here, and also you’ll undoubtedly discover it.

  40. Absolutely written content, thankyou for selective information.

  41. Thank you for sharing excellent informations. Your web-site is very cool. I’m impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found simply the info I already searched everywhere and just couldn’t come across. What an ideal web-site.

  42. I conceive you have mentioned some very interesting details, thankyou for the post.

  43. I view something genuinely special in this site.

  44. I don’t unremarkably comment but I gotta tell thanks for the post on this special one : D.

  45. Glad to be one of many visitors on this awful web site : D.

  46. Hi there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the problem resolved soon. Thanks

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

  48. I really like your writing style, wonderful info , appreciate it for putting up : D.

  49. Your style is so unique compared to many other people. Thank you for publishing when you have the opportunity,Guess I will just make this bookmarked.2

  50. Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all tabs and related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or anything, web site theme . a tones way for your customer to communicate. Nice task.

Comments are closed.