As you pointed out, both of them can be used to set the response body. I think @return is part of a typical http endpoint.
response.body () is useful for handling exceptions.
exception(NotFoundException.class, (e, request, response) -> { response.status(404); response.body("Resource not found"); });
Sparkjava is the bare base of the bones and it must be built on top. response.body () makes sparkjava easily extensible in contexts where you do not have access to the return object.
source share