Sunday 15 July 2012

how can i return 404 http status from dropwizard -


New drop-wizard! Anyway, can I return a different HTTP status code from the API? Originally something like this!

  @GET @Timed Public MyObject getMyObject (@QueryParam ("id") optional; & lt; string & gt; {MyObj myObj = myDao.getMyObject (id) if (myObj = = Null) {/ Return Status NOT_FOUND; // or something similar // or more probably // getResponseObjectFrom somewhere. Satstats (mystatus)} myObj; }  

I use the JX-RS Response object instead of returning my actual domain In response, the object acts as an excellent standard for incorporating metadata with your feedback object and provides a good manufacturer for managing status codes, headers, customer content types, etc.

  // import javax.ws.rs core. @ GET @ Reply above responded public response getMyObject (@QueryParam ("id") optional;; string> id) {MyObject myObj = myDao.getMyObject (ID) if (myObj == tap) Or other metadata if this useful return is Response.status (Response.Status.NOT_FOUND) .build ()} Return Response.ok (myObj) .build (); }  

No comments:

Post a Comment