You are previewing Developing Web Apps with Haskell and Yesod, 2nd Edition.
O'Reilly logo
Developing Web Apps with Haskell and Yesod, 2nd Edition

Book Description

This fast-moving guide introduces web application development with Haskell and Yesod, a potent language/framework combination that supports high-performing applications that are modular, type-safe, and concise. Fully updated for Yesod 1.4, this second edition shows you how Yesod handles widgets, forms, persistence, and RESTful content. Author Michael Snoyman also introduces various Haskell tools to supplement your basic knowledge of the language.

Table of Contents

  1. Preface
    1. Who This Book Is For
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
  2. I. Basics
  3. 1. Introduction
    1. Type Safety
    2. Concise Code
    3. Performance
    4. Modularity
    5. A Solid Foundation
  4. 2. Haskell
    1. Terminology
    2. Tools
    3. Language Pragmas
    4. Overloaded Strings
    5. Type Families
    6. Template Haskell
    7. QuasiQuotes
    8. API Documentation
    9. Summary
  5. 3. Basics
    1. Hello, World
    2. Routing
    3. Handler Function
    4. The Foundation
    5. Running
    6. Resources and Type-Safe URLs
    7. Non-HTML Responses
    8. The Scaffolded Site
    9. Development Server
    10. Summary
  6. 4. Shakespearean Templates
    1. Synopsis
      1. Hamlet (HTML)
      2. Lucius (CSS)
      3. Cassius (CSS)
      4. Julius (JavaScript)
    2. Types
      1. Type-Safe URLs
    3. Syntax
      1. Hamlet Syntax
      2. Lucius Syntax
      3. Cassius Syntax
      4. Julius Syntax
    4. Calling Shakespeare
      1. Alternative Hamlet Types
    5. Other Shakespeare
    6. General Recommendations
  7. 5. Widgets
    1. Synopsis
    2. What’s in a Widget?
    3. Constructing Widgets
    4. Combining Widgets
    5. Generating IDs
    6. whamlet
      1. Types
    7. Using Widgets
    8. Using Handler Functions
    9. Summary
  8. 6. The Yesod Typeclass
    1. Rendering and Parsing URLs
      1. joinPath
      2. cleanPath
    2. defaultLayout
      1. getMessage
    3. Custom Error Pages
    4. External CSS and JavaScript
    5. Smarter Static Files
    6. Authentication/Authorization
    7. Some Simple Settings
    8. Summary
  9. 7. Routing and Handlers
    1. Route Syntax
      1. Pieces
      2. Resource Name
      3. Handler Specification
    2. Dispatch
      1. Return Type
      2. Arguments
    3. The Handler Functions
      1. Application Information
      2. Request Information
      3. Short-Circuiting
      4. Response Headers
    4. I/O and Debugging
    5. Query String and Hash Fragments
    6. Summary
  10. 8. Forms
    1. Synopsis
    2. Kinds of Forms
    3. Types
    4. Converting
    5. Creating AForms
      1. Optional Fields
    6. Validation
    7. More Sophisticated Fields
    8. Running Forms
    9. i18n
    10. Monadic Forms
    11. Input Forms
    12. Custom Fields
    13. Values That Don’t Come from the User
    14. Summary
  11. 9. Sessions
    1. clientsession
    2. Controlling Sessions
    3. Session Operations
    4. Messages
    5. Ultimate Destination
    6. Summary
  12. 10. Persistent
    1. Synopsis
    2. Solving the Boundary Issue
      1. Types
      2. Code Generation
      3. PersistStore
    3. Migrations
    4. Uniqueness
    5. Queries
      1. Fetching by ID
      2. Fetching by Unique Constraint
      3. Select Functions
    6. Manipulation
      1. Insert
      2. Update
      3. Delete
    7. Attributes
    8. Relations
    9. A Closer Look at Types
      1. More Complicated, More Generic
    10. Custom Fields
    11. Persistent: Raw SQL
    12. Integration with Yesod
    13. More Complex SQL
    14. Something Besides SQLite
    15. Summary
  13. 11. Deploying Your Web App
    1. Keter
    2. Compiling
    3. Files to Deploy
    4. SSL and Static Files
    5. Warp
      1. Nginx Configuration
      2. Server Process
    6. Nginx + FastCGI
    7. Desktop
    8. CGI on Apache
    9. FastCGI on lighttpd
    10. CGI on lighttpd
  14. II. Advanced
  15. 12. RESTful Content
    1. Request Methods
    2. Representations
      1. JSON Conveniences
      2. New Data Types
    3. Other Request Headers
    4. Summary
  16. 13. Yesod’s Monads
    1. Monad Transformers
    2. The Three Transformers
    3. Example: Database-Driven Navbar
    4. Example: Request Information
    5. Performance and Error Messages
    6. Adding a New Monad Transformer
    7. Summary
  17. 14. Authentication and Authorization
    1. Overview
    2. Authenticate Me
    3. Email
    4. Authorization
    5. Summary
  18. 15. Scaffolding and the Site Template
    1. How to Scaffold
    2. File Structure
      1. Cabal File
      2. Routes and Entities
      3. Foundation and Application Modules
      4. Import
      5. Handler Modules
    3. widgetFile
    4. defaultLayout
    5. Static Files
    6. Summary
  19. 16. Internationalization
    1. Synopsis
    2. Overview
    3. Message Files
      1. Specifying Types
    4. RenderMessage typeclass
    5. Interpolation
    6. Phrases, Not Words
  20. 17. Creating a Subsite
    1. Hello, World
  21. 18. Understanding a Request
    1. Handlers
      1. Layers
      2. Content
      3. Short-Circuit Responses
    2. Dispatch
      1. toWaiApp, toWaiAppPlain, and warp
      2. Generated Code
      3. Complete Code
    3. Summary
  22. 19. SQL Joins
    1. Multiauthor Blog
    2. Database Queries in Widgets
    3. Joins
    4. Esqueleto
    5. Streaming
    6. Summary
  23. 20. Yesod for Haskellers
    1. Hello, Warp
    2. What About Yesod?
    3. The HandlerT Monad Transformer
      1. (To)Content, (To)TypedContent
      2. HasContentType and Representations
      3. Convenience warp Function
    4. Writing Handlers
      1. Getting Request Parameters
      2. Short-Circuiting
      3. Streaming
    5. Dynamic Parameters
    6. Routing with Template Haskell
      1. LiteApp
    7. Shakespeare
      1. The URL Rendering Function
    8. Widgets
    9. Details We Won’t Cover
  24. III. Examples
  25. 21. Initializing Data in the <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="keep-together">Foundation Data Type</span>
    1. Step 1: Define Your Foundation
    2. Step 2: Use the Foundation
    3. Step 3: Create the Foundation Value
    4. Summary
  26. 22. Blog: i18n, Authentication, <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="keep-together">Authorization, and Database</span>
  27. 23. Wiki: Markdown, Chat Subsite, <span xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="keep-together">Event Source</span>
    1. Subsite: Data
    2. Subsite: Handlers
    3. Subsite: Widget
    4. Master Site: Data
    5. Master Site: Instances
    6. Master Site: Wiki Handlers
    7. Master Site: Running
    8. Summary
  28. 24. JSON Web Service
    1. Server
    2. Client
  29. 25. Case Study: Sphinx-Based Search
    1. Sphinx Setup
    2. Basic Yesod Setup
    3. Searching
    4. Streaming xmlpipe Output
    5. Full Code
  30. 26. Visitor Counter
  31. 27. Single-Process Pub/Sub
    1. Foundation Data Type
    2. Allocate a Job
    3. Fork Our Background Job
    4. View Progress
    5. Complete Application
  32. 28. Environment Variables for Configuration
  33. 29. Route Attributes
    1. Alternative Approach: Hierarchical Routes
  34. IV. Appendices
  35. A. monad-control
    1. Overview
    2. Intuition
    3. Types
      1. MonadTransControl
      2. MonadControlIO
    4. Real-Life Examples
    5. Lost State
    6. More Complicated Cases
  36. B. Web Application Interface
    1. The Interface
      1. Response Body
      2. Request Body
    2. Hello, World
    3. Resource Allocation
    4. Streaming Response
    5. Middleware
  37. C. Settings Types
  38. D. http-conduit
    1. Synopsis
    2. Concepts
    3. Request
    4. Manager
    5. Response
    6. http and httpLbs
  39. E. xml-conduit
    1. Synopsis
    2. Types
      1. The Four Types of Nodes
      2. Documents
      3. Events
    3. Text.XML
      1. A Note About File Paths
    4. Cursor
    5. xml-hamlet
    6. xml2html
  40. Index