happstack-server-7.4.2: Web related tools and services.

Copyright(c) Happstack.com 2010; (c) HAppS Inc 2007
LicenseBSD3
MaintainerHappstack team <happs@googlegroups.com>
Stabilityprovisional
PortabilityGHC-only, Windows, Linux, FreeBSD, OS X
Safe HaskellNone
LanguageHaskell98

Happstack.Server

Contents

Description

Happstack.Server provides a self-contained HTTP server and a rich collection of types and functions for routing Requests, generating Responses, working with query parameters, form data, and cookies, serving files and more.

A very simple, "Hello World!" web app looks like:

import Happstack.Server
main = simpleHTTP nullConf $ ok "Hello World!"

By default the server will listen on port 8000. Run the app and point your browser at: http://localhost:8000/

At the core of the Happstack server we have the simpleHTTP function which starts the HTTP server:

simpleHTTP :: ToMessage a => Conf -> ServerPart a -> IO ()

and we have the user supplied ServerPart (also known as, ServerPartT IO), which generates a Response for each incoming Request.

A trivial HTTP app server might just take a user supplied function like:

myApp :: Request -> IO Response

For each incoming Request the server would fork a new thread, run myApp to generate a Response, and then send the Response back to the client. But, that would be a pretty barren wasteland to work in.

The model for ServerPart is essential the same, except we use the much richer ServerPart monad instead of the IO monad.

For in-depth documentation and runnable examples I highly recommend The Happstack Crash Course http://happstack.com/docs/crashcourse/index.html.

Synopsis

HTTP Server

Request Routing

Creating Responses

Looking up values in Query String, Request Body, and Cookies

Create and Set Cookies (see also Happstack.Server.RqData)

File Serving

HTTP Realm Authentication

Error Handling

I18N

Web-related Monads

Proxying

Output Validation

HTTP Types

Other