Dreamescaper / GenerateAspNetCoreClient

DotNet tool to generate HTTP client classes from ASP.NET Core api controllers.
MIT License
63 stars 5 forks source link

Add "base path" to the GenerateClientOptions #7

Closed vmachacek closed 2 years ago

vmachacek commented 2 years ago

Would it be possible to add command line switch to supply base path string so that every url generated by the tool starts with this base path?

I can take a look and produce a PR..

Dreamescaper commented 2 years ago

Can't you just include this basePath when you create a client?

                services
                    .AddRefitClient<MyClientType>()
                    .ConfigureHttpClient(c =>
                    {
                        c.BaseAddress = new Uri("https://whatever.com/my/api/v1/");
                    })
vmachacek commented 2 years ago

If I'm not mistaken this won't work with Refit because Refit requires URL start with / and thus what you sent as example would end up being https://whatever.com/my/api/v1//foo-bar considering Refit API would be decorated with [Get("/foo-bar")].

To elaborate on my use case Im using tool to generate API for testing and in some scenarios Im using WebApplicationFactory to run the API. This solved my issue

factory = new WebApplicationFactory();
factory.CreateDefaultClient(new Uri("http://localhost/api"), handlers);

No need for a base path, thanks!