3
votes

Most Haskell web application frameworks seem to focus on doing a lot of the work on server (templating, forms, etc.). However, most everyone else seem to be moving more and more of the application on the client and talking to the server via narrow REST APIs.

I'm looking to build a web app that mostly runs on the client. I'd like to base the client-side on Backbone.js (or similar) and do HTML templating fully on the client using a JavaScript templating library.

I'd like to implement the server-side in Haskell, preferably using the Snap framework.

Has anyone tried using the Snap framework this way? How can I implement a basic REST API with GET, POST, PUT, DELETE methods in Snap? Or should I go for something even simpler than Snap for my server?

1

1 Answers

4
votes

I have a website built on Snap that uses quite a bit of client side code. It might not be quite as extensive as you're thinking, but it certainly proves the point. I recommend serving javascript as static files. You can filter on HTTP methods using Snap's method function. Here's one idea for how you might use it:

fooHandler = method GET getter <|>
             method POST poster <|>
             method DELETE deleter
  where
    getter = ...
    poster = ...
    deleter = ...

Then you can use this simply by adding a route for it:

addRoutes [ ("foo", fooHandler), ... ]