Minimal Warp webserver example

前端 未结 1 341
南方客
南方客 2021-02-01 02:14

I want to create a website using the Warp webserver in Haskell.

As I\'m a Haskell beginner, examples like this one are too complex for me.

Can anyone show me a s

相关标签:
1条回答
  • 2021-02-01 03:05

    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.

    0 讨论(0)
提交回复
热议问题