Chapter 18. Understanding a Request

You can oftentimes get away with using Yesod for quite a while without needing to understand its internal workings. However, developing an understanding of its ins and outs is advantageous. This chapter will walk you through the request handling process for a fairly typical Yesod application. Note that a fair amount of this discussion involves code changes in Yesod 1.2. Most of the concepts are the same in previous versions, though the data types involved were a bit messier.

Yesod’s usage of Template Haskell to bypass boilerplate code can make it a bit difficult to understand this process sometimes. If you wish to go beyond the information in this chapter, it can be useful to view GHC’s generated code using -ddump-splices.

Note

A lot of this information was originally published as a blog series on the 1.2 release. You can see the blog posts at:

Handlers

When trying to understand Yesod request handling, we need to look at two components: how a request is dispatched to the appropriate handler code, and how handler functions are processed. We’ll start off with the latter, and then circle back to understanding the dispatch process itself.

Layers

Yesod builds itself on top of WAI, which provides a protocol for web servers (or, more generally, handlers) and applications to communicate with each other. This is expressed through two data types: Request and Response ...

Get Developing Web Apps with Haskell and Yesod, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.