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
simpleHttpServer serverFunc initialState port
simpleHttpServerprovides a simple way to create web servers (HTTP servers).
serverFunc :: a -> SimpleHttpRequest -> (a, SimpleHttpResponse)
initialState :: a
port :: Port
:8080/, if started on a computer named myhost.
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
replyWith (okResponse html
)to return a normal HTML web page.
replyWithFileapplied to the file name. The extention of the file name determines the Mime type of the returned document. The server has builtin support for the most common types of documents (html, xml, txt, jpg, gif, png, pdf, ps, mp3, ...), others are labelled with the type
saveThen. (This can be used to save the current state of the server, to allow it to be read back in if the server is restarted.)
Request and response types: HttpRequest and HttpResponse.
Functions for analysing requests: getQuery et al.
Functions for constructing server respones: okResponse et al.