Search code examples
asp.net-mvcasp.net-web-apiclient-serverdto

Should I use the same data transfer object from the server to the client and back


I am returning data from different domain repositories to my service and from the service to my Asp.net WebApi controller to the client. The data is put into a DTO.

Should I use the same DTO to transfer the data from the client to server although I would have to add some properties which are not used from server to client.

Is that approach ok or should I use different DTO`s ?


Solution

  • HTTP, and therefore WebAPI, deal in Requests and Responses. Its a matter of opinion, but I would venture that if there is even a small difference I would go ahead and make individual objects/DTOs to echo the HTTP request & response design in your code.

    This would also adhere to the Single Responsibility Principle.