Creating the client
To access the API, we need to create a client. There are many ways of doing this, but we will do it in the simplest way possible by writing the code ourselves.
The client will implement the same IBlogApi
interface. This way, we have the same code regardless of which implementation we are using, and direct JSON access with BlogApiJsonDirectAccess
or BlogApiWebClient
, which we are going to create next:
- Right-click on the Dependencies node under
BlazorWebApp.Client
and select Manage NuGet Packages. - Search for
Microsoft.AspNetCore.Components.WebAssembly.Authentication
and click Install. - Also, search for
Microsoft.Extensions.Http
and click Install. - In the
BlazorWebApp.Client
project, in the root of the project, add a new class and name itBlogApiWebClient.cs
. - Open the newly created file and add the following namespaces:
using Data.Models; using Data.Models.Interfaces; using Microsoft.AspNetCore.Components.WebAssembly.Authentication...