I'm working on a API for the logistics department, and I have a resource called logisticTransport
, which is an entity in our database. I'm facing a challenge with maintaining consistency when retrieving data from this resource.
In some parts of our application, we only need to retrieve certain fields from logisticTransport
, so we return a subset of the fields. However, in other cases, we need to retrieve the full entity, including related fields from associated entities.
This approach is causing some inconsistency because logisticTransport
sometimes contains only basic fields, and other times it includes additional related fields. It has also become challenging to synchronize these different types of responses in our codebase.
For example, I have an interface in TypeScript called LogisticTransport
, which represents the type expected by the frontend. This interface includes the basic fields. Should I create a separate interface when I want to retrieve the full LogisticTransport
resource with all the related fields? Or would it be better to use a single interface that includes all possible data, even if some fields are not always returned?
How can we structure our API to ensure consistency across different use cases while allowing flexibility in what data is retrieved? Are there best practices for handling this kind of scenario?
Thanks in advance for your help!