summaryrefslogtreecommitdiffhomepage
path: root/HTTP
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-20 17:28:19 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-20 17:32:55 -0400
commit3633c44893bfbd50f25b84ac353012975388332c (patch)
treedf4ee463ce728fc58214b1e20ce23f48a4e71e60 /HTTP
parente6097d694ca24b9546f9b7b25fc73768af9f017b (diff)
downloadkeysafe-3633c44893bfbd50f25b84ac353012975388332c.tar.gz
initial http api using servant
Diffstat (limited to 'HTTP')
-rw-r--r--HTTP/Server.hs51
1 files changed, 51 insertions, 0 deletions
diff --git a/HTTP/Server.hs b/HTTP/Server.hs
new file mode 100644
index 0000000..5df3d06
--- /dev/null
+++ b/HTTP/Server.hs
@@ -0,0 +1,51 @@
+{- Copyright 2016 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module HTTP.Server 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