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. UpvoteRocket is the leading automated voting service for private MMORPG servers. Our system climbs toplist rankings on XtremeTop100, TopG, GTop100, Top100Arena, and 20+ other platforms with intelligent automation that blends seamlessly with natural traffic. Every vote is delivered through authentic connections with realistic timing patterns to maximize success rates. Whether you run a Ragnarok, World of Warcraft, Mu Online, Lineage 2, or Perfect World server, we handle the voting so you can focus on your game. Pay only for successful votes, track progress in real-time, and watch your server rise to #1 while you sleep.

  2. Robertscals's avatar Robertscals says:

    apotek acne: l arginin apotek – Svenska Pharma

  3. Jamesmug's avatar Jamesmug says:

    cheap viagra Macksood Urology Urological Services sildenafil online

  4. Russelltix's avatar Russelltix says:

    levitra https://macksoodurology.com/ed-medications/cialis-tadalafil/ erectile dysfunction drugs online

  5. Russelltix's avatar Russelltix says:

    ED medications https://macksoodurology.shop ed medicines online

  6. Russelltix's avatar Russelltix says:

    ED medications https://macksoodurology.com/ed-medications/viagra-sildenafil/ buy ed medication online

  7. Williamisono's avatar Williamisono says:

    hГ¶rapparat prisjakt: Svenska Pharma – apotek expressleverans

  8. PatrickBep's avatar PatrickBep says:

    Viagra sans ordonnance livraison 24h Viagra prix pharmacie paris Viagra sans ordonnance livraison 48h

  9. Williamisono's avatar Williamisono says:

    Svenska Pharma: kattmalt apotek – Svenska Pharma

  10. Jeraldbasse's avatar Jeraldbasse says:

    https://mexicorx.online/# mexico pharmacies

  11. GregoryVar's avatar GregoryVar says:

    BlueLine: Viagra Tablet price – BlueLine Pharmacy

  12. Great breakdown of routing in APIs, Jesse. I’ve been working on a project where we had to decide between attribute-based and convention-based routing, and your explanation really clarified the trade-offs for me. Do you have any recommendations for handling complex nested routes while keeping the code maintainable?

  13. gullybet app's avatar gullybet app says:

    Thankyou for all your efforts that you have put in this. very interesting information.

  14. JamesAmush's avatar JamesAmush says:

    MetabolicCare: MetabolicCarePharmacy – shop medicine online

  15. Great breakdown of routing in APIs, Jesse! I appreciate how you clarified the relationship between endpoints and route parameters—it’s something that often gets confusing when moving from simple GET requests to more complex routes. Have you found any particular design patterns that help keep routing clean as the API scales? I’m currently working on a project where the routes are starting to feel a bit unwieldy.

  16. JamesSog's avatar JamesSog says:

    canadianpharmacymeds: trusted canadian pharmacy – canadian pharmacy antibiotics

  17. Jamesacutt's avatar Jamesacutt says:

    http://fleximedsindia.com/# online pharmacy india

  18. JamesSog's avatar JamesSog says:

    medicine mexico: MexiCare Direct – MexiCare Direct

  19. Jamesacutt's avatar Jamesacutt says:

    https://mexicaredirect.shop/# pharmacies in mexico

  20. Jerrywex's avatar Jerrywex says:

    Easy North RX global pharmacy canada vipps approved canadian online pharmacy

  21. JamesSog's avatar JamesSog says:

    legit canadian online pharmacy: pharmacy in canada – canada drug pharmacy

  22. Marto Tibe's avatar Marto Tibe says:

    Public policy is key here, and our states need to develop some strategies – – soon.

  23. JamesSog's avatar JamesSog says:

    canadian pharmacy 1 internet online drugstore: pharmacy canadian superstore – canadian pharmacy store

  24. Jerrywex's avatar Jerrywex says:

    online canadian drugstore Easy North RX canadian pharmacy

  25. vaser hi def's avatar vaser hi def says:

    Thanks for discussing your ideas right here. The other point is that whenever a problem occurs with a pc motherboard, people should not take the risk with repairing that themselves because if it is not done correctly it can lead to permanent damage to the complete laptop. Most commonly it is safe just to approach a dealer of that laptop for that repair of its motherboard. They have got technicians who definitely have an competence in dealing with laptop motherboard troubles and can get the right analysis and carry out repairs.

  26. Hey very nice website!! Man .. Beautiful .. Amazing .. I’ll bookmark your web site and take the feeds also?I’m happy to find a lot of useful information here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

  27. JamesSog's avatar JamesSog says:

    canadian pharmacies online: Easy North RX – Easy North RX

  28. I don?t even know how I ended up right here, however I believed this post used to be good. I do not recognise who you’re but definitely you are going to a famous blogger should you aren’t already 😉 Cheers!

  29. Josephned's avatar Josephned says:

    stromectol pills ICPS ivermectin rx

  30. BrianTed's avatar BrianTed says:

    tirzepatide https://usobesityscience.org/tirzepatide-analysis/ buy liraglutide online

  31. TimothySet's avatar TimothySet says:

    40 units of semaglutide is how many ml American Metabolic Research Institute

Leave a Reply

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