DISQUS

DISQUS Hello! Thinking inside a bigger box is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

A Brief Adventure with Universal Repositories and REST Web Services

Started by jhannes · 10 months ago

Inspired by Per Mellqvist (and myself, to be fair), I wanted to explore the possibility of using a generic DAO or Repository interface for REST. Based on this simple idea, I was able to create a very cute and testable prototype of a full Web Service stack for REST based Web Services. The m ... Continue reading »

7 comments

  • Hei Johannes,

    Sjekk ut WP-Syntax pluggen til WordPress. Vil gi deg en vakker output på kodeeksemplene dine.
  • Really elegant construction this.
    When trying to run it, I had to add 10 external jars. Makes me wonder
    if they're all really needed. Second, in the "trade" package there are
    unresolved references to the ...rest.UrlMemoryRepository class.
    Still, really cool stuff.
  • Hi, Mats

    Yeah, as it turns out, Spring is a dependency hog, and the other dependencies stack up.

    If you're not doing it already, you really should use Maven to build this (and other) project. It really helps with dependency mess.

    Sorry about the UrlMemoryRepository. I am reworking the code, and it is in a bit of an intermediate state right now. If this is a blocker for you, I can prioritize fixing it. Let me know.
  • No problem, I can manage. Just wanted to give feedback in case you weren't aware. And thanks for the Maven tip.

    Another thing is that the repository interface looks a lot like the Map interface. Make me wonder about the differences, such as method names (should "retrieve" be called "get"?), the type parameters (wouldn't it be nicer with a key type parameter?), would it be possible to go so far as to have Repository implement Map?

    Also I didn't quite like the "hack" with URLs being used interchangeably with Keys, or the "Long.valueOf(parts[1])" in RESTRepositoryServlet.getKey where Keys are suddenly assumed/restricted to be Longs.

    Not "complaining", just trying to provide some humble feedback, hoping it might be of some interest.
  • Thanks for the good comments, Mats.

    I have indeed considered using the Map interface. My main issue is how to treat keys during inserts. The Map interface is not designed for key generation purposes. I've toyed with a few options, but found none that I like.

    Using URLs as keys is actually one of the neat things about REST. This will become more obvious if I get around to publishing work on more complex models.

    Regarding "get" versus "retrieve". I choose "retrieve" because of the CRUD patterns (but I cowardly left "insert" as "create" to avoid the overloaded meaning of "insert"). Also, I wanted to remove the association with getters. But "get" might be a better name after all.
  • When GETing it's pretty clear that if an object contains a reference to another object, it is either included in the returned document, or it is referenced.
    When POSTing or PUTting, however, the situation is more complex. I don't think it matters if you are creating or updating, what to do with direct attributes are clear, but not with referenced objects. A referenced object might exist only on the client side, or it might be in the repository, but with different attributes. Do you have a clear vision of how to handle this?
  • Hi, Mats

    I'm thinking about GET as analogous to lazy loading proxies with Hibernate (or other persistence framework). This means that a GET request could either return a link, or the embedded object. Using the same analogy, PUT and POST requests can be similar to cascading saves, I think. This means that the onus is on the client to ensure that the correct state is transferred.

    Does that make sense?

Add New Comment

Returning? Login