From 5f737f2ebbd0fdaf5013b8de95e59ab0bd9098f2 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 9 Oct 2015 17:26:57 -0400 Subject: Include code to pass a request header to servant. --- src/Main.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index ba1acd4..3eed3cc 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -20,10 +20,10 @@ import Control.Monad.IO.Class import Control.Monad.Trans.Either defineFlag "port" (8081 :: Int) "Port to serve on" -defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" +defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" defineFlag "pending_path" ("" :: String) "Path to pending albums" defineFlag "photos_path" ("" :: String) "Path to permanent albums" -$(return []) +$(return []) -- Somehow forces the flags to be set. instance ToJSON Album instance FromJSON Album @@ -38,6 +38,8 @@ instance ToJSON RenameError type PhotoApi = "albums" :> Get '[JSON] [Album] :<|> "rename" :> ReqBody '[JSON] RenameRequest :> Post '[JSON] (Either RenameError ()) + :<|> "test" :> Header "X-Token" String :> Get '[JSON] () +-- Introduce request header containing auth information. config = Config { pendingPath = flags_pending_path @@ -47,6 +49,7 @@ config = Config server :: Server PhotoApi server = albums :<|> rename + :<|> test where albums = liftIO (getAlbums config) @@ -54,6 +57,8 @@ server = albums rename (RenameRequest from to) = liftIO $ runEitherT (renameAlbum config from to) + test token = return () + photoApi :: Proxy PhotoApi photoApi = Proxy -- cgit v1.2.3