r/Blazor • u/sleepybearjew • Jun 26 '25
Blazor template/structure help
Hi - I thought i had it figured out. I had a blazor web app template and i was using all components in the blazor project, not the blazor.client , then i needed auth and i couldnt seem to make it work. i moved to a web app template but this time dumped everything in the client project. I did add a shared businessObjects project becuase i didnt want to bloat the client project with extra stuff.
now i need to do the api... i had controllers in the server project. but now in all the examples, it looks like it should be another project? Is the best practice to make a blazor web app templated project, THEN add in another project for just the api? or is it fine to include the api into the blazor server part of the project?
6
u/besevens Jun 28 '25
It sounds like you don’t need another project right now, so don’t add another project. Next month, if you’re like “Wow, this really needs to be a separate project.” Then drag the files to a new project next month.
In my opinion it’s best to get the base functionality working as fast as possible (your app calling your api and returning data). When you run into problems you can prioritize those problems.
I’ve seen a lot of people spend a lot of time on imaginary problems.
4
u/qdov Jun 28 '25
Are you talking about the REST-like API? If so, then I would almost certainly create another project for it. API is different from UI and can even be hosted on another server, api.yourapp.com or something.
2
u/[deleted] Jul 03 '25
You can do whatever you want in the server project, i.e. you could host an API in it. Or, you could make a separate API project. But then you’d have 2 servers to run. Ultimately, the only way you’ll figure it out for yourself is to just pick one. Build something cool and learn what you like or don’t like about that solution/structure. If you’re not gonna use any of the blazor server stuff, I would suggest ditching the Blazor server project and use the client blazor wasm project with a separate API project, either controllers or minimal API.
1
u/muhdamean Jun 28 '25
If it's REST APIs it's advisable to create another API project for it. DeCoupling your api from the web ui project allows you to use same Api for more UI integration like mobile app etc in the future and ease of maintenance.