vendredi 31 mars 2023

Managing DTO and BO in a project calling an API

I'm working on a backend layer of a webapp in Java which is essentially an RESTful API (using Spring Boot). Within my backend I'm calling another API (essentially my database) to retrieve and combine data. Current my workflow for handling a GET request looks the following

  1. Receive request within my API
  2. Call the other API (database), and map it's JSON response to a DTO
  3. Convert DTO to BO to perform logic on it
  4. Return BO via spring boot (which turns its fields into a JSON body and returns this)

My question is
Following the DTO logic, would it be more correct to turn my BO into a second DTO, containing the data to be transferred (as I understand it is discouraged to transfer data with a BO)

Essentially this would add a step to my list above, between 3 and 4:
---> ...
---> 3.5. Convert BO to new DTO
---> 4. Return DTO via sprint boot

The reason I haven't done this is because it seems a bit intensive to convert objects twice, however I see the benefits to the DTO / BO pattern.

Aucun commentaire:

Enregistrer un commentaire