Skip to content

RestAPI

Declarative HTTP client interfaces (Refit-style attributes) with implementations generated at compile time.

Packages

PackageReturn types
Observables.RestAPI.R3Task<T>, R3 Observable<T>, …
Observables.RestAPI.ReactiveTask<T>, IObservable<T>, …

Both include the Observables.RestAPI runtime. Reactive package also needs System.Reactive (and may require R3 at runtime for shared core types).

Define an API

csharp
using Observables.RestAPI;
using R3;

public interface IUserApi
{
    [Get("/users/{id}")]
    Task<User> GetUserAsync(int id);

    [Get("/users/{id}")]
    Observable<User> GetUserObservable(int id);
}

var api = RestService.For<IUserApi>(httpClient);
User user = await api.GetUserAsync(42);
User reactive = await api.GetUserObservable(7).FirstAsync();

Use FirstAsync (with a cancellation token in apps) for single-response observables. Errors surface as ApiException (same family as Refit).

System.Reactive

csharp
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;

User user = await api.GetUserObservable(7).FirstAsync().ToTask();

Diagnostics

See Diagnostics.

Samples

Released under the MIT License.