In some books, the rest APIs generally return a Response object which wraps some other objects representing payload, status, etc.
On the other hand many of the APIs that I have seen and written return a POJO (or call it a DTO) as JSON which is the consumed by the client.
This may be opinion based, but I would like to know which is better of the two to use on high scalability environment where some request result in success and others in failure/data not returned.
I would like to know if there is an accepted better practice. This will help me designing some APIs and put things in perspective before my team. But I am ok with this question being closed if 'better of the two' is too much opinion based.
Thanks.
Update: The two rest APIs would look like this. Avoiding code like @Path, @Get, @PathParam, @Produces etc
public Response myCustomerObject(int id){...}
This returns a Customer object wrapped inside the Response object. Response could be error as well.
And the approach below will return the Customer entity directly:
public Customer myCustomerObject(int id){...}