Chapter 7: Creating an API
Blazor WebAssembly needs to be able to retrieve data and also change our data. For that to work, we need to have an API with which we can access the database. In this chapter, we will create a Web API.
When we are using Blazor Server, the API will be secured together with the page (if we add an Authorize
attribute), so we get that for free. But with WebAssembly, everything will be executed in the browser, so we need something that WebAssembly can communicate with to update the database on the server.
To do this, we will cover need to cover three topics. In this chapter, we will cover the first two:
- Creating the service
- Creating the client
The third topic is Calling the API, but we won't cover that part in this chapter; instead, we will come back to it in Chapter 9, Sharing Code and Resources.