We are developing a system with coarse microservice architecture. We have an API that uses controllers and back-end logic with Entity-Framework repository, and several types of clients that use this API, all in dotnet, therefore, typesafe.
We need to use some sort of data transfer objects for communication between the API and the clients. Clients are using REST calls. However, our controllers need to hide some properties of the entities for:
different clients (e.g. metadata of entity for web clients and no metadata for mobile clients)
different controller actions (e.g.
/Users/
returns a list ofUser
DTOs having only name and surname, whereas/Users/{id}
returns user details. )different REST methods (e.g. a
Post
requests would not have timestamps as it is created server-side)
My question is: what would be a good design for reusability? Is the best practice creating new classes for all requests/responses? We wouldn't want to use dynamic objects. I thought of Builder pattern, but I am not sure if that fits here.