Asked by:
Blazor Server App Project With API

Question
-
User-702421929 posted
Hi All,
I am developing a Blazor Server App for my company that will run mostly in the local network.
I have future plans to expose data for employees on mobile app.
Will the best practice be to separate the Blazor Server App and the API into two projects (less convenient) or define all the services and controls within the Blazor Server App ?
In addition will API defined in Blazor Server App can support REST and ODATA the same as pure WEB API Project ?
Many thanks
Yaron
Wednesday, November 25, 2020 8:38 PM
All replies
-
User475983607 posted
A Blazor Web Assembly project is a better approach.
Will the best practice be to separate the Blazor Server App and the API into two projects (less convenient) or define all the services and controls within the Blazor Server App ?Create separate applications if you plan to share Web API with other client besides the Blazor application.
In addition will API defined in Blazor Server App can support REST and ODATA the same as pure WEB API Project ?Web API is a REST service and you can use ODATA if you like.
https://devblogs.microsoft.com/odata/asp-net-odata-8-0-preview-for-net-5/
Wednesday, November 25, 2020 9:39 PM -
User-474980206 posted
While you can mix blazor server (signalr hub) and webapi in the same project it does not make sense. You are mixing UI and server code. As suggested if you used blazor WASM, then it and the mobile app would be using the same server code and api. You would only need to write and maintain one api.
Thursday, November 26, 2020 3:56 PM -
User-702421929 posted
Thanks guys,
It seems to me like I am missing something, so please correct me if I am wrong.
What does it matter if I use the same project for UI and server if that project type allows me to do so (you must agree that it is more convenient) and in additional it's API exposed to other apps ?
Isn't that the whole Idea of Blazor Server App in contrary to all other frameworks that it is not possible to so even if you wanted to ?
Thanks
Thursday, November 26, 2020 7:23 PM -
User475983607 posted
What does it matter if I use the same project for UI and server if that project type allows me to do so (you must agree that it is more convenient) and in additional it's API exposed to other apps ?You can do what ever you like. We're simply recommending standard design practices.
Isn't that the whole Idea of Blazor Server App in contrary to all other frameworks that it is not possible to so so even if you wanted to ?I'm not exactly sure what you're asking. Blazor Server runs on the server so it does not make sense to make an browser HTTP request when there is a perfectly good SignalR connection. But Hey, it's your design.
Thursday, November 26, 2020 7:43 PM -
User-474980206 posted
You asked best practice.
when I start a web application, I have a several projects to start
- Ui project - website often spa, and public api
- webapi project - the application web interface, internal interface behind firewall
- api project - the sdk to call the web api
- application project - the business logic for the application
- database project - database schema and deployment scripts
- database api project - api for accessing the database
Thursday, November 26, 2020 9:28 PM -
User-702421929 posted
I'm not exactly sure what you're asking. Blazor Server runs on the server so it does not make sense to make an browser HTTP request when there is a perfectly good SignalR connection. But Hey, it's your design.If I understand what you are saying, then yes, this is exactly my point. If I use Blaser Server App that run on the server why should I put the API in other project and use http request to consume data from that API ?
Correct me if I am wrong but I think that the only real reason in my case will be security if in some point I will want to access the UI from the internet, right ?
Friday, November 27, 2020 9:04 PM -
User475983607 posted
If I understand what you are saying, then yes, this is exactly my point. If I use Blaser Server App that run on the server why should I put the API in other project and use http request to consume data from that API ?Blazor Server has a persistent SignalR connection to the server. A typical Blazor application uses this connection to execute code on the server like query a table. Can you explain why you want to add Web API when you already have the capability to execute code on the server? Why do you want to make a separate connection to the server?
Correct me if I am wrong but I think that the only real reason in my case will be security if in some point I will want to access the UI from the internet, right ?I guess that's one reason. The other reason is following best practices are explained several times in this thread. It seems you have already made up your mind and are not interested in our recommendations.
Friday, November 27, 2020 10:48 PM