Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staticwebdev/blazor-starter
A starter template in C# APIs and Blazor for Azure Static Web Apps
https://github.com/staticwebdev/blazor-starter
azure azure-functions azure-static-web-apps blazor dotnet
Last synced: 4 days ago
JSON representation
A starter template in C# APIs and Blazor for Azure Static Web Apps
- Host: GitHub
- URL: https://github.com/staticwebdev/blazor-starter
- Owner: staticwebdev
- Created: 2020-09-21T13:24:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-24T13:34:27.000Z (8 months ago)
- Last Synced: 2024-04-15T12:16:35.172Z (7 months ago)
- Topics: azure, azure-functions, azure-static-web-apps, blazor, dotnet
- Language: CSS
- Homepage:
- Size: 385 KB
- Stars: 217
- Watchers: 15
- Forks: 104
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Blazor Starter Application
This template contains an example .NET 8 [Blazor WebAssembly](https://docs.microsoft.com/aspnet/core/blazor/?view=aspnetcore-6.0#blazor-webassembly) client application, a .NET 8 C# [Azure Functions](https://docs.microsoft.com/azure/azure-functions/functions-overview), and a C# class library with shared code.
## Getting Started
1. Create a repository from the [GitHub template](https://docs.github.com/en/enterprise/2.22/user/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) and then clone it locally to your machine.
1. In the **Api** folder, copy `local.settings.example.json` to `local.settings.json`
1. Continue using either Visual Studio or Visual Studio Code.
### Visual Studio 2022
Once you clone the project, open the solution in the latest release of [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) with the Azure workload installed, and follow these steps:
1. Right-click on the solution and select **Configure Startup Projects...**.
1. Select **Multiple startup projects** and set the following actions for each project:
- *Api* - **Start**
- *Client* - **Start**
- *Shared* - None1. Press **F5** to launch both the client application and the Functions API app.
### Visual Studio Code with Azure Static Web Apps CLI for a better development experience (Optional)
1. Install (or update) the [Azure Static Web Apps CLI](https://www.npmjs.com/package/@azure/static-web-apps-cli) and [Azure Functions Core Tools CLI](https://www.npmjs.com/package/azure-functions-core-tools).
1. Open the folder in Visual Studio Code.
1. Delete file `Client/wwwroot/appsettings.Development.json`
1. 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:
```bash
dotnet run
```In the API folder, run:
```bash
func start
```In another terminal, run:
```bash
swa start http://localhost:5000 --api-location http://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.
1. Open a browser and navigate to the Static Web Apps CLI's address at `http://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.
1. Enter Ctrl-C to stop the Static Web Apps CLI.
## Template Structure
- **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## Deploy to Azure Static Web Apps
This application can be deployed to [Azure Static Web Apps](https://docs.microsoft.com/azure/static-web-apps), to learn how, check out [our quickstart guide](https://aka.ms/blazor-swa/quickstart).