Created
January 29, 2017 07:08
-
-
Save naoto-ogawa/e7fb930c7c0b356072348970df7afa1a to your computer and use it in GitHub Desktop.
Reading a file in Servant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Servant | |
import Control.Monad.IO.Class -- liftIO | |
import Network.Wai.Handler.Warp -- run | |
type FileRead01 = "sample01.txt" :> Get '[PlainText] String | |
myAPI01 :: Proxy FileRead01 | |
myAPI01 = Proxy | |
app01 :: Application | |
app01 = serve myAPI01 server01 | |
server01 :: Server FileRead01 | |
server01 = do | |
f <- liftIO (readFile "sample01.txt") | |
return f | |
main01 :: IO () | |
main01 = run 8080 app01 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment