InternetLib

simpleHttpServer, SimpleHttpRequest, et al

HTTP Servers

Types

simpleHttpServer :: (a -> SimpleHttpRequest -> (a, SimpleHttpResponse)) -> a -> Port -> IO ()
type SimpleHttpRequest = (Host, CalendarTime, HttpRequest String)
data SimpleHttpResponse
replyWith :: HttpResponse -> SimpleHttpResponse
replyWithFile :: FilePath -> SimpleHttpResponse
saveThen :: (FilePath, String) -> SimpleHttpResponse -> SimpleHttpResponse

Synopsis

simpleHttpServer serverFunc initialState port

Description

simpleHttpServer provides a simple way to create web servers (HTTP servers).

Arguments

serverFunc :: a -> SimpleHttpRequest -> (a, SimpleHttpResponse)
This is the function that implements your server. When applied to the current state and a request, it should return a new state and a response.
initialState :: a
The initial state of the server. For stateless servers, you can use ().
port :: Port
The number of the port the server will be listening for requests at. Web servers usually use port 80, but servers started by users without special privileges may be restricted to port numbers above 1024. Often 8080 is used, which means the server will be available at URL http://myhost:8080/, if started on a computer named myhost.

A SimpleHttpRequest contains the name of the host connecting to the server, the time at which the connection was made, and the HttpRequest received from the client (browser). In the request, the URL is represented as a string.

There are three ways to construct SimpleHttpResponse to be returned by the server:

See Also

Request and response types: HttpRequest and HttpResponse.

Functions for analysing requests: getQuery et al.

Functions for constructing server respones: okResponse et al.


InternetLib