Open obsean opened 3 years ago
I haven't really worked with Observables with Refit. Could you briefly explain in which cases IObservable return type would be more beneficial comparing to Task?
Generally if you are working with the reactive extensions then it is preferable to use IObservable, more for consistencies sake then anything else. So when using ReactiveUI, this would be preferable.
the change would be that instead of the:
`//
using System.Collections.Generic; using System.Threading.Tasks; using Refit; using Shared;
namespace Api.Client
{
public interface IWeatherForecastApi
{
[Get("/WeatherForecast")]
Task<IEnumerable
it should generate this:
`//
using System; using System.Collections.Generic; using Refit; using Shared;
namespace Api.Client
{
public interface IWeatherForecastApi
{
[Get("/WeatherForecast")]
IObservable<IEnumerable
Sorry for delay! There is a couple of other similar cases, e.g. to use Task\<IApiResponse\<T>> or Task\<HttpResponseMessage>.
So I'm thinking, maybe it would be better to parametrize it? Add two parameters - void-response-type
and non-void-response-type
.
In your case, something like
void-response-type "IObservable<{T}>" non-void-response-type "IObservable<HttpResponseMessage>"
Would that help?
Good catch!
Looking at the samples I think these are the only return types:
Task
Task<HttpResponseMessage>
Task<T>
Task<ApiResponse<T>>
Observable<HttpResponseMessage>
Observable<T>
Observable<ApiResponse<T>>
Note that there is no generic System.Observable
I think that the best way of representing this would be with 3 switches, something like:
--return-observables --return-httpresponsemessage-for-void --return-apiresponse-for-non-void
Note that --return-observables will always assume --return-httpresponsemessage-for-void
you might also want to combine the last 2, because for example a method that returns Task will throw on a failure while a method that returns Task
Hope this makes sense and thanks for your time
Refit allows a return type if Task or IObservable. It would be nice if there was a flag to replace Tasks with Iobservables