DEV Community

Angelo Pirola
Angelo Pirola

Posted on

How to use SignalR in a Blazor WebAssembly and Web API project

This post was born from a personal need during the development of a notification system in a festival management application, which I am currently developing (the source can be found in this repository).

There will be a need to implement a notification service in the client part (frontend), but the notifications will have to be generated automatically by the backend part.

Faced with this need in the short term, I created this example repository, which contains two client projects (client and client2), and a server project (server).

By starting the server and client projects, you can have a demo of signalR generates notifications in a razor page, with the help of Mudblazor these notifications have a different color based on the severity.

In this example, it was chosen to use the "notify-client" endpoints generating the notification in grey and "notify-client-info" generating the notification in light blue.

To generate these notifications you can use swagger of the backend project, testing the endpoints that contain the nomenclature "notify-client"

Instead, by starting the server and client projects, you can have a demo of signalR that generates notifications in a Razor page, with the help of Mudblazor the notifications will all have the same color, in this case gray and in the backend part the endpoint to use will be the one called "notify-client2", alternatively you can use the button on the frontend "Send notification"

If you like my open source works don't forget to "follow me" on GitHub and/or click the repository's starred button.

Top comments (0)