Skip to content
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

Drop WithClient extension methods #590

Closed
Richiban opened this issue Jan 13, 2021 · 3 comments
Closed

Drop WithClient extension methods #590

Richiban opened this issue Jan 13, 2021 · 3 comments

Comments

@Richiban
Copy link

Richiban commented Jan 13, 2021

[Original bug report]

The following code:

async Task Main()
{
	var client = new FlurlClient("http://localhost");
	
	var result = await "/"
		.WithClient(client)
		.GetAsync();
		
	Console.WriteLine(result);
}

worked on v2.x but on v3 it throws the error:

FlurlHttpException: Call failed. An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set. GET /

It seems a bug was introduced where the base URL can't be set on the client any more.

@Richiban Richiban added the bug label Jan 13, 2021
@tmenier
Copy link
Owner

tmenier commented Jan 13, 2021

Thanks for reporting. This could be legitimate if the behavior changed, although I will say WithClient is a bit of a relic and I don't think it's used much since the Request method was introduced in 2.0. Honestly, I kind of forgot it existed and might have considered deprecating it.

Nowadays I would recommend not doing this:

"/".WithClient(client)

and instead doing this:

client.Request("/")

@Richiban
Copy link
Author

Thanks for the reply; we've updated our code with your suggestion.

On researching this issue when it first appeared it does seem that we're doing things a bit unusually in using the WithClient method. I originally discovered it only by looking at the (extension) methods available on IFlurlRequest.

I agree that this method should either be fixed or deprecated.

Thanks again!

@tmenier tmenier added the 4.0 label May 5, 2022
@tmenier tmenier changed the title v3 broke setting a base URL on the FlurlClient Drop WithClient extension method Jun 10, 2022
@tmenier tmenier changed the title Drop WithClient extension method Drop WithClient extension methods Jun 10, 2022
@tmenier
Copy link
Owner

tmenier commented Jun 10, 2022

WithClient will be removed in the next 4.0 prerelease. I'm struggling to think of a use case where client.Request(...) isn't better/cleaner (or at least just as good), but if anyone has such a case feel free to describe it here. I could be persuaded to change my mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Released
Development

No branches or pull requests

2 participants