All of these are on .NET Core 3.1
I've created an MVC project with individual user accounts stored in-app for authentication and I will be using it as an api. The API looks like this:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET: api/Values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/Values/5
[HttpGet("{id}", Name = "Get")]
public string Get(int id)
{
return "value";
}
}
and a Blazor Server-side project to fetch data from that API.
@page "/fetchvalues"
@using System.Net.Http
<h3>FetchValues</h3>
<button @onclick="GetData">Get values</button>
@if (output != null)
{
<table>
@foreach (var item in output)
{
<tr>
<td>@item</td>
</tr>
}
</table>
}
@code {
private HttpClient client = new HttpClient();
private List<string> output = null;
private async void GetData()
{
output = await client.GetJsonAsync<List<string>>("http://localhost:5001/api/values");
}
}
