As discussed earlier, any response from a RESTful service may include:
- Status code
- Response entity
- Content type
By default, any RESTful service that runs and returns normally without any problems will contain the status code 200 (OK). The response entity will be these value you return from the RESTful method. The content type will be these one specified by the @Produces annotation, as mentioned earlier.
Sometimes, you may need to customize the details of the response yourself at runtime, in one of the following scenarios:
- The response entity data type/MIME content type is not known until runtime
- A custom status code should be returned to the client according to some business logic inside the RESTful service code