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

[Question/Feature request] Support for synchronous methods #992

Closed
hankovich opened this issue Nov 1, 2020 · 6 comments
Closed

[Question/Feature request] Support for synchronous methods #992

hankovich opened this issue Nov 1, 2020 · 6 comments
Labels

Comments

@hankovich
Copy link

HttpClient in .NET 5 received synchronous Send methods.
I'm interested if future versions of refit will use these methods to allow sync methods inside refit interfaces.
Do you have such plans?

Current behavior:

public interface IApi
{
    [Get("/ping")]
    ApiResponse<Response> Ping(CancellationToken cancellationToken = default);
}

api.Ping() throws InvalidCastException with the following message:

Unable to cast object of type 'TaskToObservable`1[AwesomeProject.Response]' to type 'Refit.ApiResponse`1[AwesomeProject.Response]'.

@clairernovotny
Copy link
Member

clairernovotny commented Nov 1, 2020

Not likely, sync HTTP is pretty much a giant hack. Network I/O is async by definition. What is the issue with Task<ApiResponse<Response>>?

@hankovich
Copy link
Author

There are cases when you just can't use async methods. For example, when you are implementing an existing sync interface.

@rodion-m
Copy link

rodion-m commented Nov 8, 2020

This is became a necessity to call refit methods from C++/CLI code (it doesn't support async/await). I was forced to use SyncHttpClient from this repo https://github.com/pierodetomi/dotnet-webutils .

@jrummell
Copy link

jrummell commented Dec 2, 2020

I have to support ASP.NET MVC 4 projects, and there are places such as AuthorizeAttribute implementations that have no async support. I'm having to write different API client libraries that are async based on Refit (for all the new, shiny projects) and synchronous based on RestSharp (for all of the old stuff I have to maintain). I would love to use Refit everywhere.

@clairernovotny
Copy link
Member

I'm closing this as won't fix. Refit may not be able to handle the edge cases where sync is required.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants