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

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. 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. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty 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 13 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. Matthewjap's avatar Matthewjap says:

    viagra canadian pharmacy: indian pharmacies safe – bitcoin pharmacy online

  2. RalphWok's avatar RalphWok says:

    can you buy antibiotics over the counter Antibiotics Pharmacology cheapest antibiotics

  3. Richardroony's avatar Richardroony says:

    Over the counter antibiotics for infection OTC antibiotics п»їbuy antibiotics

  4. It?s exhausting to find educated folks on this topic, however you sound like you realize what you?re talking about! Thanks

  5. RalphWok's avatar RalphWok says:

    buy antibiotics for uti OTC antibiotics buy doxycycline antibiotics

  6. RalphWok's avatar RalphWok says:

    online antibiotics Institute for Antimicrobial Research prescription antibiotic

  7. RalphWok's avatar RalphWok says:

    can you buy antibiotics over the counter Institute for Antimicrobial Research best online doctor for antibiotics

  8. Richardroony's avatar Richardroony says:

    uti antibiotics online IARP otc uti medicine

  9. Dewayneshign's avatar Dewayneshign says:

    https://pharmacologicalsciences.com/cialis.html Pharmacological Sciences Research Institute

  10. Anthonylag's avatar Anthonylag says:

    https://pharmacologicalsciences.com/ Pharmacological Sciences

  11. Andreimiva's avatar Andreimiva says:

    viagra Pharmacological Institute Pharmacological Institute

  12. Whitneysnolf's avatar Whitneysnolf says:

    buy ed medication online Pharmacological Sciences best online ed pills

  13. Williamnourl's avatar Williamnourl says:
  14. StevenAwank's avatar StevenAwank says:

    jojobet güncel giriş: jojobet

  15. RichardGlarK's avatar RichardGlarK says:

    jojobet güncel adres jojobet

  16. MichaelStago's avatar MichaelStago says:

    https://novamenpharmacy.com/# Cheap generic Viagra online

  17. Arthurnor's avatar Arthurnor says:

    CoreVital Pharmacy: Cialis over the counter – CoreVital Pharmacy

  18. MichaelStago's avatar MichaelStago says:

    http://corevitalpharmacy.com/# CoreVital Pharmacy

  19. CarlosTag's avatar CarlosTag says:

    where can i get ed pills: ed pills pharmacy – online prescription for ed

  20. Hectorzenna's avatar Hectorzenna says:

    buy ed pills online: online ed pharmacy – erectile dysfunction drugs online

  21. MichaelStago's avatar MichaelStago says:

    https://novamenpharmacy.com/# Viagra online price

  22. Anthonypam's avatar Anthonypam says:

    https://medicobridgerx.com/# mexican pharmacies near me

  23. Patrickfuh's avatar Patrickfuh says:

    indian pharmacy online: TrustRx India – indianpharmacy com

  24. Thomassnice's avatar Thomassnice says:

    medicine from mexico: MedicoBridge RX – MedicoBridge RX

  25. scalp brush's avatar scalp brush says:

    Hey! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be bookmarking and checking back often!

  26. RichardGit's avatar RichardGit says:

    True Health Pharm: True Health Pharm – cheapest online ed meds

  27. PatrickZoolf's avatar PatrickZoolf says:

    True Health Pharm: True Health Pharm – True Health Pharm

  28. GregoryRox's avatar GregoryRox says:

    mostbet casino: mostbet

  29. GregoryRox's avatar GregoryRox says:

    mostbet kasyno: mostbet

  30. BennieWalse's avatar BennieWalse says:

    mostbet güncel adres: mostbet

  31. CurtisInses's avatar CurtisInses says:

    https://cassiteleri.top/# casino deneme siteleri

  32. aqua sculpt's avatar aqua sculpt says:

    **aqua sculpt**

    AquaSculpt is a high-quality metabolic support supplement created to help the body utilize fat more efficiently while maintaining steady, reliable energy levels throughout the day.

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

  34. gptimg2img's avatar gptimg2img says:

    The way Jesse breaks down routing in Azure Functions really helps clarify how flexible and powerful endpoint design can be. I especially appreciate the example showing how to enforce parameter types and make IDs optional — it’s a small detail that makes a big difference in API robustness. This is exactly the kind of practical guidance that makes API development less error-prone and more maintainable.

  35. Thanks , I have just been looking for info about this subject for ages and yours is the best I’ve discovered till now. But, what about the bottom line? Are you sure about the source?

  36. Dewalive's avatar Dewalive says:

    Usually I don’t read post on blogs, however I would like to say that this write-up very forced me to take a look at and do so! Your writing taste has been surprised me. Thanks, quite great article.

Leave a Reply

Your email address will not be published. Required fields are marked *