SkillAgentSearch skills...

BlazorWithRefit

Very simple demo of Blazor on wasm with Refit and System.Text.Json

Install / Use

/learn @richbryant/BlazorWithRefit
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

BlazorWithRefit

Very simple demo of Blazor on wasm with Refit, Polly and System.Text.Json

Short Form -

Take a look in Program.cs, it contains pretty much everything you need. The Polly stuff is marked with a comment, feel free to remove it if you don't want Polly.

Longer version

This is an AspNetCore Hosted basic template, all I've done is swap out the direct call to WeatherForecastController with a service that uses Refit.

As you can see, it's a straightforward Refit service marked with a [Get] attribute.

    public interface IWeatherService
    {
        [Get("/WeatherForecast")]
        Task<WeatherForecast[]> GetForecasts();
    }

Naturally, that's injected into FetchData.razor instead of the usual HttpClient.

All the setup for this is in program.cs as mentioned above, but in order to use System.Text.Json - which is the new default for AspNetCore - instead of Refit's preferred NewtonSoft.Json, you also need to override the default serializer. This is really simple. Just copy mine. You'll find it here. The setup for this is in the settings variable in program.cs. I could have inlined it but it's clearer this way.

Take what you need, go, enjoy cleaner RESTful Api calls from Blazor on wasm!

Related Skills

View on GitHub
GitHub Stars10
CategoryDevelopment
Updated6mo ago
Forks0

Languages

C#

Security Score

67/100

Audited on Oct 10, 2025

No findings