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.