I have struggled for years with foo bar examples and Telerik Documentation that does not contain any examples acquiring the data for a Grid that does not assume that you are using jsonp or odata. I am trying to populate a Blazor Grid with data from a simple REST API over which I have no control.
Do you have any examples that show this? I haven't been able to find any.
I would like to to be able to capture the data from the remote API (e.g. metaweather) and use that data to populate the grid. Here's an example of a demo Blazor app where I populate an html table using that API:
page "/weather"
@using System.Net.Http.Json
@inject IHttpClientFactory _clientFactory
<h3>WeatherData</h3>
@if (string.IsNullOrWhiteSpace(errorString) == false)
{
<h2 style="color: red;">@errorString</h2>
}
else if (forecast is null)
{
<div class="h4">Loading...</div>
}
else
{
<table class="table table-stripped">
<thead class="thead-dark">
<tr>
<th>Date</th>
<th>Weather State</th>
<th>Low</th>
<th>High</th>
</tr>
</thead>
<tbody>
@foreach (var w in forecast.consolidated_weather)
{
<tr>
<td>@w.applicable_date </td>
<td>@w.weather_state_name </td>
<td>@w.min_temp </td>
<td>@w.max_temp </td>
</tr>
}
</tbody>>
</table>
}
@code {
VancouverForecast forecast;
string errorString;
protected override async Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://www.metaweather.com/api/location/9807");
var client = _clientFactory.CreateClient();
HttpResponseMessage response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
forecast = await response.Content.ReadFromJsonAsync<VancouverForecast>();
errorString = null;
}
else
{
errorString = $"There was an error getting our forecast: {response.ReasonPhrase}()";
}
}
}
My eventual goal is to create a properly structured app with separation of concerns doing this sort of thing. Anything you could point me to to assist me in that goal would be greatly appreciated.