Stuck in the middle : Weblog

From knowledgebase
Jump to navigation Jump to search

URL

http://www.jroller.com/rickard/entry/the_domain_model_as_rest

Description

The domain model as REST anti-pattern

Today JavaLobby published yet another domain-model-as-REST article, using Spring and Jersey. As already pointed out, this really is an anti-pattern, and is not RESTful, and cannot be so either.

The point that all of these types of articles miss is the HATEOAS part, the hyperlinking of resources. If you expose your domain model, basically saying "here's all I got, use as you see fit", there is no sensible way to create links between resources that expose the application state. There is no sensible way to tell the client "here's what you can do next", because the "REST" API allows anything at any time.

Here's an example, from my own app, which showed me the problem with this approach. I have users in my system. I need two ways to work with their passwords: the user must be allowed to change his own password, and the administrator shall be allowed to reset any users' password. In the beginning, when I was exposing my domain model, the URL's for thi