Tuesday, April 21, 2009

Routes and zippers and CRUD, oh my

i've taken an interest in the recent developments around the zipper construction. Like every other developer on the planet i've long noticed that there is a close relationship between paths into locations in a data structure and URLs in a CRUD application that is essentially backed by such a data structure. Recently, i've noticed that efforts like merb routes and Jersey/JAX-RS are groping toward a similar notion in an effort to simplify and semi-automate RESTful design. i submit that the zipper/context calculation pretty much completely captures this relation. Here's a link to a discussion of how to calculate zipper for any (regular) data type. Moreover, it seems to me, the relationally-definable types (i.e. the ones that end up with natural mappings to a type defined in a relational schema) are entirely included in the types susceptible to the zipper calculation.

To be clear, i'm suggesting that given a type, T, you can use zipper to auto-calculate
  • Context data, C[T], that will serve as the type of paths into T.
  • These paths have a natural interpretation as URLs to locations in an inhabitant (aka instance) of T.
  • The type+focus combination gives a natural place to hang the CRUD operations.
Note that with a context type you can validate URLs on the client side; i.e., you can eliminate with a client-side check many cases where you would otherwise be forced to serve up a 404.

Finally, there is a natural extension of this framework to more generally distributed data. As usual, it appears that Oleg got to the observation before i did, and this seems to be the basis of his ZFS file system.

No comments: