title: Which is better: returning a Response object or an Object representing the rest resource?
body: <p>In some books, the rest APIs generally return a Response object which wraps some other objects representing payload, status, etc.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thanks.</p>
  
  <p>Update:
  The two rest APIs would look like this. Avoiding code like @Path, @Get, @PathParam, @Produces etc</p>
  
  <pre><code>public Response myCustomerObject(int id){...} 
  </code></pre>
  
  <p>This returns a Customer object wrapped inside the Response object. Response could be error as well.</p>
  
  <p>And the approach below will return the Customer entity directly:</p>
  
  <pre><code>public Customer myCustomerObject(int id){...} 
  </code></pre>