Creating and composing snaplets
In this recipe, we will create a snaplet and build the Snap application around it. We will also use the heist
snaplet for serving the HTML templates. This recipe will demonstrate the following:
- How to create a snaplet
- How to use an existing snaplet inside another existing snaplet
- How the snaplet data is structured and placed
- How to access snaplet data
How to do it...
- Create a new project,
working-with-snaplets
, with thesimple
stack template:
stack new working-with-snaplets simple
- Add a dependency on the
snap-core
library in thebuild-depends
subsection of theexecutable
section, as follows:
executable working-with-snaplets hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 , snap-core , snap-server , snap , lens , bytestring ...