java - Which is better: returning a Response object or an Object representing the rest resource? -
in books, rest apis return response object wraps other objects representing payload, status, etc.
on other hand many of apis have seen , written return pojo (or call dto) json consumed client.
this may opinion based, know better of 2 use on high scalability environment request result in success , others in failure/data not returned.
i know if there accepted better practice. me designing apis , put things in perspective before team. ok question being closed if 'better of two' opinion based.
thanks.
update: 2 rest apis this. avoiding code @path, @get, @pathparam, @produces etc
public response mycustomerobject(int id){...} this returns customer object wrapped inside response object. response error well.
and approach below return customer entity directly:
public customer mycustomerobject(int id){...}
i vote api gives response object. allows control response within code , clear going response. , in cases want write response cannot represented pojo not forced use unintuitive workarounds.
returning object rest handler method transformed response framework magic taste.
worst - imho - practice return string rest handler method interpreted template reference (e.g. path jsp resource) written response. again way magic.
Comments
Post a Comment