Hi!
We have a little toy project developed with play and until now only served used HTML pages. We mostly followed REST principles, identified resources and implemented HTML pages to GET them or POST changes. But, now we would like to expose those resources as a JSON API.
So for get delivering multiple formats is a no brainer. Image a route for "GET /person", we can easily use the Accept header to identify the expected format of the response payload.
But I wonder how to parse POST request payload like this. Let's say a user creates a Person using a HTML form. The controller takes the request and maps the request payload into objects of class Person and pass it over to a repository where it gets persisted. But how can I use the same function of the controller when the request payload is in JSON?
I think of the following solution: A route like "POST /person" selects the controller function to call depending on the Accept header. This means there may be multiple definitions of the same URL pattern routing to different controllers. In this case we could use one uri but provide multiple implementations. The advantage of this approach is, that HTML, JSON and XML logic is not mixed in the same controller function. Is this possible in Play?
Are there any other approaches?