THIS TUTORIAL IS STILL WORK IN PROGRESS
Welcome curious stranger. You have wandered into tutorial which aims to help you grasp the Snap and Heist Haskell modules via building a simple dynamic website.
- For your own good, read the following articles first:
- You should be comfortable with the concept of monads.
Apart from the basic and standard modules, you will need these:
- snap -- [github] | [haddock]
- snap-core -- [github] | [haddock]
- snap-server -- [github] | [haddock]
- snap-extension-mongodb -- [github] | [haddock]
- heist -- [github] | [haddock]
- mongoDB -- [github] | [haddock]
- bson -- [github] | [haddock]
Take a look at the
pastie.cabal for details
You only need a text editor or IDE of your choice, GHC and cabal (I would presonally recommend cabal-dev).
In this littel project, we will be abiding the rules of what is usually called the MVC architecture. The reason is simple -- it makes your code more modular and thus hopefully easier to reason about and maintain.
Disclaimer: These design decisions are in no way related to the Snap & Heist itself, you do not have to follow them in your projects.
Model should provide API to retrieve and store data (in our case in database).
Our model resides in the
src/Model directory. It's job is:
- to communicate with a database (i.e. writing and reading),
- to present data in suitable form to the controller.
Controller is the place where the application logic resides.
Our controller resides in the
src/Controller directory. It's job is:
- to manipulate the data it got from the model and prepare them to be presented to the user (e.g. retrieve a post),
- to convert the data it got from users to suitable form for the model (e.g. handle a form).
In Snap & Heist terms, this is the place where we implement most of our splices (ideally all of them).
View is the mediator between application and the user.
Our view resides in the
resources/templates directory. It's job is:
- to display the data from controller to the user,
- to provide an input facilities (e.g. a HTML form).
In Snap & Heist terms, the view consists of the Heist templates where we call the controller's splices.