This module defines a generic web application interface. It is a common protocol between web servers and web applications.
The overriding design principles here are performance and generality . To
address performance, this library is built on top of the enumerator and
blaze-builder packages. The advantages of enumerators over lazy IO have been
debated elsewhere and so will not be addressed here. However, helper functions
like responseLBS
allow you to continue using lazy IO if you so desire.
Generality is achieved by removing many variables commonly found in similar
projects that are not universal to all servers. The goal is that the Request
object contains only data which is meaningful in all circumstances.
Please remember when using this package that, while your application may compile without a hitch against many different servers, there are other considerations to be taken when moving to a new backend. For example, if you transfer from a CGI application to a FastCGI one, you might suddenly find you have a memory leak. Conversely, a FastCGI application would be well served to preload all templates from disk when first starting; this would kill the performance of a CGI application.
This package purposely provides very little functionality. You can find various middlewares, backends and utilities on Hackage. Some of the most commonly used include:
- data Request = Request {}
- data Response
- type ResponseEnumerator a = (Status -> ResponseHeaders -> Iteratee Builder IO a) -> IO a
- responseEnumerator :: Response -> ResponseEnumerator a
- type Application = Request -> Iteratee ByteString IO Response
- type Middleware = Application -> Application
- data FilePart = FilePart {}
- responseLBS :: Status -> ResponseHeaders -> ByteString -> Response
WAI interface
Information on the request sent by the client. This abstracts away the details of the underlying implementation.
Request | |
|
type ResponseEnumerator a = (Status -> ResponseHeaders -> Iteratee Builder IO a) -> IO aSource
type Application = Request -> Iteratee ByteString IO ResponseSource
type Middleware = Application -> ApplicationSource
Middleware is a component that sits between the server and application. It can do such tasks as GZIP encoding or response caching. What follows is the general definition of middleware, though a middleware author should feel free to modify this.
As an example of an alternate type for middleware, suppose you write a function to load up session information. The session information is simply a string map [(String, String)]. A logical type signatures for this middleware might be:
loadSession :: ([(String, String)] -> Application) -> Application
Here, instead of taking a standard Application
as its first argument, the
middleware takes a function which consumes the session information as well.
Response body smart constructors
responseLBS :: Status -> ResponseHeaders -> ByteString -> ResponseSource