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 IMyBlogApi interface. This is so we have the exact same code regardless of which implementation we are using, direct JSON access with BlogApiJsonDirectAccess or BlogApiWebClient, which we are going to create next:
- Right-click on the Dependencies node under Data 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 Data project, add a new class and name it BlogApiWebClient.cs.
- Open the newly created file.
- Add IMyBlogApi to the class and make it public like this:
namespace Data;
public class BlogApiWebClient : IBlogApi
{
}
- Some of the API calls are going to be public (do not require authentication), but HttpClient will be configured to...