Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created July 3, 2018 11:58
Show Gist options
  • Save christiannagel/de3dc9d8a3bd21ed512f68e055c6ce4b to your computer and use it in GitHub Desktop.
Save christiannagel/de3dc9d8a3bd21ed512f68e055c6ce4b to your computer and use it in GitHub Desktop.
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