Minimal Warp webserver example

我们两清 提交于 2019-12-02 18:49:58
Uli Köhler

Here's a minimal Hello World application using Warp 3.0+. Run it, then navigate to http://localhost:3000. This example will show Hello world.

In order to keep this example minimal, URL paths are not handled at all (the same content is delivered for any path). For a slightly longer example incorporating URL path handling, see the Haskell Wiki

{-# LANGUAGE OverloadedStrings #-}

import Network.Wai (responseLBS, Application)
import Network.Wai.Handler.Warp (run)
import Network.HTTP.Types (status200)
import Network.HTTP.Types.Header (hContentType)

main = do
    let port = 3000
    putStrLn $ "Listening on port " ++ show port
    run port app

app :: Application
app req f =
    f $ responseLBS status200 [(hContentType, "text/plain")] "Hello world!"

Update 2014-06-20: Warp 3.0 included some API changes -- reflect them back in the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!