Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server example with conduit #2

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/streamingServerConduit.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}

module Servant.Streaming.Example (main) where

import Data.Conduit (($$))
import Data.Conduit.List as CL
import qualified Data.Conduit.Combinators as CC
import Servant
import Network.Wai.Handler.Warp (run)

import Servant.Streaming.Server
import Streaming hiding (run)
import qualified Streaming.Prelude as S


type API = "getfile" :> StreamResponseGet '[OctetStream]

server :: Server API
server = return $ hoist lift (CC.sourceFileBS "bigfile") $$ CL.mapM_ S.yield

api :: Proxy API
api = Proxy

app1 :: Application
app1 = serve api server

main :: IO ()
main = do
print "serving on 8081"
run 8081 app1