✅ Is it worth having an abstractions "layer" for a web API?
I'm working on a website project using an ASP.NET web API for the backend and Blazor WASM for the frontend.
Since I'll one way or another need to call my web API from the Blazor project through an
HttpClient
, would it be worth abstracting this into its own project with classes which act as almost "front-ends" for the API itself with strongly typed methods corresponding to the API endpoints? Or would it just be more straightforward to just call the API through a raw HttpClient
in the Blazor project?4 Replies
Yeah, a project with shared classes, or even ready-made typed clients as well, could be a good idea
That way if you add some property to some
PersonDto
, it gets added both in your backend and frontend code, so both need to deal with that change
You don't risk the models of the data you exchange divergingYeah, I already have a shared project containing all the models
You got the minimum covered, then. Whether you want the typed clients to be in that project, in some other project, or just in a folder in your Blazor project is up to preference, I'd say
sure