tmenier / Flurl

Fluent URL builder and testable HTTP client for .NET
https://flurl.dev
MIT License
4.23k stars 387 forks source link

#673 allow to access FlurlCall in RespondWith #825

Open RytisLT opened 6 months ago

RytisLT commented 6 months ago

Minimal change that adds FlurlCall to RespondWith allowing to create response based on request parameters like body, query parameters, etc.

tmenier commented 6 months ago

Thanks. I'll look at this more closely when I have some time, but I like the general idea. I'm wondering if a FlurlRequest arg instead of FlurlCall might be enough? It seems intuitive: "given this request, return this response". Also, I could see people wanting to do this with RespondWith(string) and RespondWithJson(object) too, since those are probably more commonly used than the low-level method. So we might want overloads for those.

RytisLT commented 6 months ago

@tmenier I've changed Func<FlurlCall, HttpContent> to Func<IFlurlRequest, HttpContent> and added the two overloads for string and Json. There is one caveat, to get to request body I need to call request.Content.ReadAsStringAsync().Result since I cannot await in the non-async method. To make it proper async we would need to introduce RespondWithAsync, this would require more changes to the code. I could take a stab at it if you want.

RytisLT commented 6 months ago

@tmenier would you like to see any more changes to the PR or does it look good the way it is?

RytisLT commented 6 months ago

@tmenier can you please have a look at the PR I really need this feature for my project. Thanks!

RytisLT commented 5 months ago

@tmenier any chances on getting this merged?

tmenier commented 5 months ago

New features are more than just a merge. I haven't had time to work on the next sprint so you'll have to be patient or use your own fork.

RytisLT commented 5 months ago

Roger that. Can I help you out in any way?