Created
July 3, 2018 11:58
-
-
Save christiannagel/de3dc9d8a3bd21ed512f68e055c6ce4b to your computer and use it in GitHub Desktop.
Blazor Books component accessing an Azure Function returning Book objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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