Building HTTP responses
Actions process HTTP requests and return HTTP responses. So far, you have seen how HTTP requests were routed by the framework to call your application's code. Now, let's see how you can reply with HTTP responses.
An HTTP response has a status code and some optional headers and can be followed by a body. So, to build a response, you have to at least supply a status code.
For instance, your current action definitions return HTTP responses with status code 501 (Not Implemented). Try changing it to Ok
(or ok()
in Java) and reload the page in your browser (or perform a request with cURL), you should get a response with status code 200 (OK)
. Play provides helpers to build responses with common status codes. Examples of other predefined ...
Get Play Framework Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.