We have implemented a RESTful web service using the Spring Hateoas project. This project makes it easy to convert your domain classes to resources that provides "self" links etc.
What I find confusing with this approach is that you return resources classes when using GET, but when it comes to do a POST or a PUT you use the domain model. This means that any client using the RESTful API would need to have access to the domain classes + the resource classes (resulting in clients having to add the Hateoas project as a dependency). This approach can be seen in this blog entry.
What would be the correct approach here? To only work with resources classes (for POSTs and PUTs as well)?
Not each domain class has an matching resource. Take the case where the object graph is more complicated and a resource has a list of child object:
public class StoreResource {
public String name;
public List<Location> children;
}
The Location object wouldn't have any resource class.
For now it looks like we need to provide both the domain classes + existing resource classes to clients.