Should one API be used for performing multiple task

(shweta singh) #1

If the API is to update dates in a table(PATCH Call),should the same API be used to calculate the earliest date and update it in another column of the same table.If yes should there be different error message to indicate which part of the API failed.

Details of the table: The table consists of employee details, so there are two columns where “when the employee joined” is entered and another column indicates which employee among a particular department joined first.

(Joe) #2

Great API question and it can have an answer that has a testing bias!

In my opinion, an API should perform a single, small task for the reason you expressed and to maintain some simplicity. To that end, a small, single, simple task is MORE testable than a complex set of tasks that cannot be easily isolated.

I agree with you that it will be difficult to provide feedback on which task succeeds and which one does not. While it possible to manage the tasks and their associated errors, that management would also require more testing. However, that kind of design seems like the start of technical debt, and could indicate to someone maintaining that API that this kind of design choice is acceptable. In my opinion, small/single/simple is a better choice for an API because that makes the API more testable now and in the future.