This sample demonstrates how get the weather data from a WebAPI exposed on the Blazor server app which is called from the .NET MAUI client. I started with the .NET MAUI Blazor Hybrid and Web template maui-blazor-web
and moved the weather generator code from the Weather.razor component to a WeatherService on the server which implements IWeatherService. This interface is injected into the Weather.razor component so that it calls the code directly on the server but uses the httpClient on the .NET MAUI Client.
...UI code is the same...
Note that this class uses an HttpClientHelper
class that manages the HttpClient configuration for use while debugging on simulators and emulators.
We need to add the service implementation to the builder:
We need to add the service implementation to the builder:
As well as expose the weather API: