java - Spring REST best practice for method types -
i building spring restfull service , have following method retrieves place object based on given zipcode:
@requestmapping(value = "/placebyzip", method = requestmethod.get) public place getplacebyzipcode(@requestparam(value="zipcode") string zipcode) { place place = placeservice.placebyzip(zipcode); return place; }
is best practice have return type of "place"? imagine difficult error handling?
using latest versions of spring restfull web service believe returning 'object' practise allows simplify code , specific on returning. see typing api response.
a practise error handling use controller advice utility supplied spring.
have read of:
https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
this allows throw exceptions @ of service layers , produce nice helpful error response.
Comments
Post a Comment