Persistent Plugs

March 19, 2010

GravatarMichael Snoyman

Sorry if the title sounds like a medical condition...

Anyway, it's been quite busy since releasing the Yesod web framework. I got a lot of very useful feedback, especially from Jeremy Shaw and Chris Eidhof. There are two main shortcomings of Yesod (and Haskell web programming in general) that we've discussed:

  • Persistence
  • Type-safe URL handling

We've had a very good discussion about the latter on the web-devel mailing list; I highly recommend that everyone subscribe to that list by the way.

That discussion inspired me a little bit for a persistence interface, and so I started a project today called persistent. The goal is to provide a unified interface to any storage backend, be it SQL, in-memory, YAML files, or Amazon SimpleDB.

At the moment, it only handles String and Int data, allows all CRUD actions and the ability to filter in a very basic way. All of this will need to be augmented to be usable, but it shows the overall structure fairly well. I've also written an in-memory sample storage mechanism; everything together clocks in at a single 145 line file.

But that's not the cool part. The cool part is synthesizing these two goals to get completely pluggable web components. As an example, I wrote up a basic web authentication plugin. All of the code is available in the same repository, and is only 164 lines- including a lot of boilerplate HTML.

The approach taken for both sides of the puzzle here is to provide a low-level, tedious, boilerplate-requiring interface that gives the user a lot of power. Both of these pieces can then be automated later through some higher-level mechanism, be it template haskell, generics or (my favorite) quasi-quoting.

If you want to try out the auth example, I've hard-coded michael/michael as the only username/password combination that works. Eventually, when we hammer out a good API for both sides of this, I would like to actually develop a fully-functional authentication plug-in that supports e-mail validation, allows OpenID, Twitter and other external logins, and more. And then any system that supports persistent and the web plug-in system will be able to have a very advanced authentication system for free.


comments powered by Disqus