summaryrefslogtreecommitdiffhomepage
path: root/HTTP/Server.hs
blob: a6b0f2d75e39057c8d1ec6f8856e329342c83727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# LANGUAGE OverloadedStrings #-}

{- Copyright 2016 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module HTTP.Server (runServer) where

import HTTP
import Types
import Types.Storage
import Serialization ()
import Servant.API
import Servant.Server
import Data.Proxy
import Network.Wai
import Network.Wai.Handler.Warp

runServer :: Int -> IO ()
runServer port = run port app

app :: Application
app = serve userAPI server

userAPI :: Proxy HttpAPI
userAPI = Proxy

server :: Server HttpAPI
server = apiVersion
	:<|> motd
	:<|> proofOfWorkRequirement
	:<|> getObject
	:<|> putObject
	:<|> countObjects

apiVersion :: Handler APIVersion
apiVersion = return (APIVersion 1)

motd :: Handler Motd
motd = return $ Motd "Hello World!"

proofOfWorkRequirement :: Handler (Maybe ProofOfWorkRequirement)
proofOfWorkRequirement = return $ Just $ ProofOfWorkRequirement 3 1

getObject :: StorableObjectIdent -> Maybe ProofOfWork -> Handler StorableObject
getObject _i _pow = undefined

putObject :: StorableObjectIdent -> Maybe ProofOfWork -> StorableObject -> Handler StoreResult
putObject _i _pow _o = return StoreSuccess

countObjects :: Maybe ProofOfWork -> Handler CountResult
countObjects _pow = return $ CountResult 42