on 13664a2 help sign in
servant/src/Servant/Server.hs
27 lines 790 B history raw
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Servant.Server where
5import Data.Proxy
6import Network.HTTP.Types
7import Network.Wai
9-- * Implementing Servers
11-- | 'serve' allows you to implement an API and produce a wai 'Application'.
12serve :: HasServer layout => Proxy layout -> Server layout -> Application
13serve p server = toApplication (route p server)
15toApplication :: RoutingApplication -> Application
16toApplication ra = \ request respond -> do
17 m <- ra request
18 case m of
19 Nothing -> respond $ responseLBS notFound404 [] "not found"
20 Just response -> respond response
22type RoutingApplication =
23 Request -> IO (Maybe Response)
25class HasServer layout where
26 type Server layout :: *
27 route :: Proxy layout -> Server layout -> RoutingApplication