I’m designing a public API for a system. I’m having doubts where should I put calculations or domain logic, should it reside on the API or on the client that will consume it?
Let say we have a Banking System, where should I put the logic for calculating cash amounts? Shall the consumer only call the Deposit method of the API and let the API handle the
calculations?
API will be built using ASP.NET WebApi
Thanks
Not sure if I fully understand your issue here but the business logic should be handled by the API (I wonder how the reverse would be).
From the implementation standpoint, you should handle them as services to decouple the system so that you can unit test it easily. For example, the below one is your
CalcService:Then, this service should be injected into your controller as below:
To make it work, you should register your service through your IoC container.