Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blazor Books component accessing an Azure Function returning Book objects
@page "/books"
@using BooksLib
@inject HttpClient Http
<h1>Books Sample</h1>
<p>This component demonstrates fetching data from Azure Functions.</p>
<p>Status: @message</p>
@if (books == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Publisher</th>
</tr>
</thead>
<tbody>
@foreach (var book in books)
{
<tr>
<td>@book.Title</td>
<td>@book.Publisher</td>
</tr>
}
</tbody>
</table>
}
@functions {
Book[] books;
string message;
protected override async Task OnInitAsync()
{
message = "OnInitAsync";
Http.BaseAddress = new Uri("https://blazorapi.azurewebsites.net");
books = await Http.GetJsonAsync<Book[]>("/api/BooksFunction");
message = "downloaded books";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.