最小的warp webserver例子 [英] Minimal warp webserver example
问题描述
我想在Haskell中使用 warp web服务器创建一个网站。由于我是一名Haskell初学者,因此这一对于我来说是复杂的。
任何人都可以向我展示一个简单的,最简单的例子: warp ?
注意:这个问题故意显示没有研究成果,因为它被回答为Q& A-Style。
以下是使用warp 3.0+的最简单的 Hello World 应用程序。运行它,然后导航到 http:// localhost:3000
。此示例将显示 Hello world
。
为了保持此示例最小化,URL路径根本不处理(相同的内容交付给任何路径)。有关合并URL路径处理的稍长示例,请参阅 Haskell Wiki
{ - #LANGUAGE OverloadedStrings# - }
导入Network.Wai(responseLBS,Application)
import Network.Wai.Handler.Warp(run)
import Network.HTTP.Types(status200)
import Network.HTTP.Types.Header(hContentType)
main = do
让port = 3000
putStrLn $侦听端口++显示端口
运行端口应用程序
应用程序::应用程序
应用程序请求f =
f $ responseLBS status200 [(hContentType,text / plain)]Hello world!
更新2014-06-20: warp 3.0包含一些API更改 - - 将它们反射回代码中。
I want to create a website using the warp webserver in Haskell. As I'm a Haskell beginner, examples like this one are to complex for me.
Can anyone show me a simple, minimal example of how to use warp?
Note: This question intentionally shows no research effort as it was answered Q&A-Style.
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.
这篇关于最小的warp webserver例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!