title: Test Snap Web Framework Handler
body: <p>I want to write little integration tests for my Snap web handlers but I am stuck. Here is the scenario. I have a Snap web handler that (run-of-the-mill style) CRUDs up a type and it looks something like this:</p>
  
  <pre><code>create :: AppHandler ()
  create = method POST $ do
           lastName  &lt;- decodeUtf8 . fromJust &lt;$&gt; getParam "lastName"
           firstName &lt;- decodeUtf8 . fromJust &lt;$&gt; getParam "firstName"
           createPerson $ Person firstName lastName
           modifyResponse (setResponseCode 204)
  </code></pre>
  
  <p>The <code>Snap.Test</code> module has some things to help build up a request and I use it to make a request for my handler:</p>
  
  <pre><code>createOwnerReq :: RequestBuilder IO () 
  createOwnerReq = postUrlEncoded "host/person/create" $
                   fromList [ ("firstName", ["Greg-Shaw"])
                            , ("lastName",  ["Snoy'Sullivan"])
                            ]
  </code></pre>
  
  <p>Here's the problem, I want to make a TestUnit TestCase for this handler so I need the run the handler on the <code>createOwnerReq</code> request. The module <code>Snap.Test</code> provides:</p>
  
  <pre><code> runHandler :: MonadIO a =&gt; RequestBuilder m () -&gt; Snap a -&gt; m Response
  </code></pre>
  
  <p>so</p>
  
  <pre><code> ... do 
       resp &lt;- runHandler createOwnerReq ??? 
  </code></pre>
  
  <p>But wait!!! My request handler is of type <code>AppHandler ()</code> but <code>runHandler</code> requires a Handler of type <code>Snap a</code>.
  How do I lift my <code>AppHandler</code> type into the <code>Snap</code> monad? Help please, this is kind of trippin' me out.</p>