Developing Web Applications with Haskell and Yesod: Safety-Driven Web Development

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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. You’ll work with several samples to explore the way Yesod handles widgets, forms, persistence, and RESTful content. You also get an introduction to various Haskell tools to supplement your basic knowledge of the language.

By the time you finish this book, you’ll create a production-quality web application with Yesod’s ready-to-use scaffolding. You’ll also examine several real-world examples, including a blog, a wiki, a JSON web service, and a Sphinx search server.


Build a simple application to learn Yesod’s foundation datatype and Web Application Interface (WAI)
Use Shakespearean template languages for HTML, CSS, and Javascript output
Produce cleaner, more modular code by learning how Yesod monads interact
Implement the yesod-form declarative API to build forms on top of widgets
Learn how Yesod and Haskell store session data and handle persistence
Use techniques to serve an HTML page and a machine-friendly JSON page from the same URL
Create reusable components for several applications with Yesod subsites

Author(s): Michael Snoyman
Edition: 1
Publisher: O'Reilly Media
Year: 2012

Language: English
Pages: 298

Table of Contents
Preface
Who This Book Is For
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgements
Part I. Basics
Chapter 1. Introduction
Type Safety
Concise
Performance
Modular
A Solid Foundation
Introduction to Haskell
Chapter 2. Haskell
Terminology
Tools
Language Pragmas
Overloaded Strings
Type Families
Template Haskell
QuasiQuotes
Summary
Chapter 3. Basics
Hello World
Routing
Handler Function
The Foundation
Running
Resources and Type-Safe URLs
The Scaffolded Site
Development Server
Summary
Chapter 4. Shakespearean Templates
Synopsis
Hamlet (HTML)
Cassius (CSS)
Lucius (CSS)
Julius (JavaScript)
Types
Type-Safe URLs
Syntax
Hamlet Syntax
Tags
Interpolation
Attributes
Conditionals
Maybe
Forall
Case
With
Doctype
Cassius Syntax
Lucius Syntax
Julius Syntax
Calling Shakespeare
Alternate Hamlet Types
Other Shakespeare
General Recommendations
Chapter 5. Widgets
Synopsis
What’s in a Widget?
Constructing Widgets
Combining Widgets
Generate IDs
whamlet
Types
Using Widgets
Summary
Chapter 6. Yesod Typeclass
Rendering and Parsing URLs
joinPath
cleanPath
defaultLayout
getMessage
Custom Error Pages
External CSS and JavaScript
Smarter Static Files
Authentication/Authorization
Some Simple Settings
Summary
Chapter 7. Routing and Handlers
Route Syntax
Pieces
Types of Pieces
Resource Name
Handler Specification
Dispatch
Return Type
Arguments
The Handler Monad
Application Information
Request Information
Short Circuiting
Response Headers
Summary
Chapter 8. Forms
Synopsis
Kinds of Forms
Types
Converting
Create AForms
Optional Fields
Validation
More Sophisticated Fields
Running Forms
i18n
Monadic Forms
Input Forms
Custom Fields
Summary
Chapter 9. Sessions
Clientsession
Controlling Sessions
Session Operations
Messages
Ultimate Destination
Summary
Chapter 10. Persistent
Synopsis
Solving the Boundary Issue
Types
Code Generation
PersistStore
Migrations
Uniqueness
Queries
Fetching by ID
Fetching by Unique Constraint
Select Functions
SelectOpt
Manipulation
Insert
Update
Delete
Attributes
Relations
Closer Look at Types
Custom Fields
Persistent: Raw SQL
Integration with Yesod
Summary
Chapter 11. Deploying Your Webapp
Compiling
Warp
Configuration
Server Process
FastCGI
Desktop
CGI on Apache
FastCGI on lighttpd
CGI on lighttpd
Part II. Advanced
Chapter 12. RESTful Content
Request Methods
Representations
RepHtmlJson
News Feeds
Other Request Headers
Stateless
Summary
Chapter 13. Yesod’s Monads
Monad Transformers
The Three Transformers
Example: Database-Driven Navbar
Example: Request Information
Summary
Chapter 14. Authentication and Authorization
Overview
Authenticate Me
Email
Authorization
Conclusion
Chapter 15. Scaffolding and the Site Template
How to Scaffold
File Structure
Cabal File
Routes and Entities
Foundation and Application Modules
Import
Handler Modules
widgetFile
defaultLayout
Static Files
Conclusion
Chapter 16. Internationalization
Synopsis
Overview
Message Files
Specifying Types
RenderMessage Typeclass
Interpolation
Phrases, Not Words
Chapter 17. Creating a Subsite
Hello World
Part III. Examples
Chapter 18. Blog: i18n, Authentication, Authorization, and Database
Chapter 19. Wiki: Markdown, Chat Subsite, Event Source
Chapter 20. JSON Web Service
Server
Client
Chapter 21. Case Study: Sphinx-Based Search
Sphinx Setup
Basic Yesod Setup
Searching
Streaming xmlpipe Output
Full Code
Part IV. Appendices
Appendix A. monad-control
Overview
Intuition
Types
MonadTransControl
MonadControlIO
Real Life Examples
Lost State
More Complicated Cases
Appendix B. Conduit
Conduits in Five Minutes
Structure of This Chapter
The Resource Monad Transformer
Goals
How It Works
Some Type Magic
Definition of ResourceT
Other Typeclasses
Forking
Convenience Exports
Source
State
sourceState and sourceIO
Sinks
Types
Sinks: no helpers
Sinks: with Helpers
List Functions
Connecting
Conduit
Types
Simple Conduits
Stateful Conduits
Using Conduits
Data Loss
SequencedSink
Buffering
Inversion of Control
A web server
Whither the request body?
BufferedSource
Typeclass
Recapping the Web Server
Appendix C. Web Application Interface
The Interface
Response Body
Request Body
Hello World
Middleware
Appendix D. Settings Types
Appendix E. http-conduit
Synopsis
Concepts
Request
Manager
Response
http and httpLbs
Appendix F. xml-conduit
Synopsis
Types
The Four Types of Nodes
Documents
Events
Text.XML
A Note About File Paths
Cursor
xml-hamlet
xml2html