With Razor pages, we had Get and Put Handlers whose code was executed on the server side, for example when a form was posted or even with a simple OnGet call. What is the equivalent of that in Blazor? I can hookup code to an onclick event for example, but that code executes in the browser (Blazor wasm), is that correct? How would I go about executing code on the server? Is web API the only solution under Blazor?
I can hookup code to a onclick event for example, but that code executes in the browser (Blazor wasm), is that correct?
Correct, the code will run in the browser for client wasm version of Blazor. You can inject a HttpClient
and make http calls just like in other SPA frameworks. The weatherforcast sample in the default template does exactly that. Also see the docs for more info.
How would I go about executing code on the server?
You will need an endpoint implementation on the server side that will accept and proccess the request send by the clients. For example REST apis with json works like that.
Sample doc for implementing REST api in asp.net core. The hosted version of the template includes REST api sample as well.
Is web API the only solution under Blazor?
No, gRPC is also a good approach, or SignalR. Depends on the use case.