Last post Nov 06, 2015 11:39 PM by Carol S Williams
Oct 21, 2015 11:31 AM|Raha06|LINK
I'm wondering about the best practice regarding a client web application consuming a restfull service implemented with the Web API approach.
The Web API retreives any kind of business data from the database. Let's say there is a service that retreives a list of customers. The return type of the GET method is List<Customer>.
So Customer is a class defined in the model of the Web API project. Fine.
In my client web application, I use the HttpClient object to consume the Web API service. I want to display on a page the customers that are pulled by the service.
Do I need to duplicate the Customer class? this is to say, to create the exact same class in my client web application?
Or can I create a separate class library project and have both the web API and the client web application reference the same shared library?
what is the best practice?
At least, when using the WCF service approach, the client application has access to a proxy class generated by the framework. There was no doubt.
Oct 21, 2015 04:08 PM|krokonoster|LINK
As for myself:
I never, ever expose my domain objects via an API (or anything else for the matter)
Instead create a Dto class (Data Transfer Object), map the domain object to the dto and have the api return that.
Yes, in many cases, the dto will look the same as the domain model but this give you so much flexibility (computed properties for instance) and also allow you to "Hide" things client applications have no business seeing.
Just my 20cents. Looking at the forums, I see so many post where guys connect their database inside a controller and return the domain object to the view as a view model. Make me weep for humanity.
Nov 06, 2015 11:39 PM|Carol S Williams|LINK