This template contains an example .NET 8 Blazor WebAssembly client application, a .NET 8 C# Azure Functions, and a C# class library with shared code.
-
Create a repository from the GitHub template and then clone it locally to your machine.
-
In the Api folder, copy
local.settings.example.json
tolocal.settings.json
-
Continue using either Visual Studio or Visual Studio Code.
Once you clone the project, open the solution in the latest release of Visual Studio 2022 with the Azure workload installed, and follow these steps:
-
Right-click on the solution and select Configure Startup Projects....
-
Select Multiple startup projects and set the following actions for each project:
- Api - Start
- Client - Start
- Shared - None
-
Press F5 to launch both the client application and the Functions API app.
-
Install (or update) the Azure Static Web Apps CLI and Azure Functions Core Tools CLI.
-
Open the folder in Visual Studio Code.
-
Delete file
Client/wwwroot/appsettings.Development.json
-
In the VS Code terminal, run the following command to start the Static Web Apps CLI, along with the Blazor WebAssembly client application and the Functions API app:
In the Client folder, run:
dotnet run
In the API folder, run:
func start
In another terminal, run:
swa start https://localhost:5000 --api-location https://localhost:7071
The Static Web Apps CLI (
swa
) starts a proxy on port 4280 that will forward static site requests to the Blazor server on port 5000 and requests to the/api
endpoint to the Functions server. -
Open a browser and navigate to the Static Web Apps CLI's address at
https://localhost:4280
. You'll be able to access both the client application and the Functions API app in this single address. When you navigate to the "Fetch Data" page, you'll see the data returned by the Functions API app. -
Enter Ctrl-C to stop the Static Web Apps CLI.
- Client: The Blazor WebAssembly sample application
- Api: A C# Azure Functions API, which the Blazor application will call
- Shared: A C# class library with a shared data model between the Blazor and Functions application
This application can be deployed to Azure Static Web Apps, to learn how, check out our quickstart guide.