Skip to content

Route Templates for HttpClient #7564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
koenigst opened this issue Feb 14, 2019 · 2 comments
Closed

Route Templates for HttpClient #7564

koenigst opened this issue Feb 14, 2019 · 2 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question

Comments

@koenigst
Copy link

Issue

We are currently building a suite of applications using the microservice design-pattern. One of our big pain-points and a frequent source of errors is building the URLs to access resources on other microservices.

Desired Solution

ASP.NET Core route templates would offer a powerful and well-known syntax for generating URLs. I would like to have a simple solution for creating URLs from route templates and be able to use them together with HttpClient for accessing ASP.NET Core APIs. This could look like:

var uri = RouteBuilder.FromTemplate("/api/{id}").With("id", 1).BuildUri();
httpClient.GetAsync(uri);

My preferred solution would be to have a Microsoft.Extensions.* package that contains the route template logic, including URL matching and generating.

Alternatives

  • LinkGenerator already has similar capabilities but it is designed to work for the Web-API being served and not for different Web-API being accessed via HTTP.
  • It is quite simple to build a custom implementation of this using TemplateParser and TemplateBinder but those types require "pubternal" types (e.g. UriBuildingContext), which means the custom implementation could break at any time.
@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Feb 14, 2019
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us, @koenigst.
@rynowak any suggestions here?

@mkArtakMSFT
Copy link
Contributor

@koenigst rather than manually constructing URLs manually, you should consider generating a client based on the swagger document of your service and then just calling methods passing proper parameters to them. This is an area we're making active improvements and things will get even simpler in the near future: #4896

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question
Projects
None yet
Development

No branches or pull requests

4 participants