aboutsummaryrefslogtreecommitdiff
path: root/lib/API.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/API.hs')
-rw-r--r--lib/API.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/API.hs b/lib/API.hs
new file mode 100644
index 0000000..3fb4c3c
--- /dev/null
+++ b/lib/API.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE UndecidableInstances #-}
+
+
+module API where
+
+import Data.Map (Map)
+import Data.Swagger (Swagger)
+import GTFS
+import Persist
+import Servant (Application, FromHttpApiData (parseUrlPiece),
+ Server, err401, err404, serve, throwError,
+ type (:>))
+import Servant.API (Capture, FromHttpApiData, Get, JSON, Post,
+ ReqBody, type (:<|>) ((:<|>)))
+
+type API = "stations" :> Get '[JSON] (Map StationID Station)
+ :<|> "timetable" :> Capture "Station ID" StationID :> Get '[JSON] (Map TripID (Trip Deep))
+ :<|> "trip" :> Capture "Trip ID" TripID :> Get '[JSON] (Trip Deep)
+ -- ingress API (put this behind BasicAuth?)
+ -- TODO: perhaps require a first ping for registration?
+ :<|> "trip" :> "register" :> Capture "Trip ID" TripID :> Post '[JSON] Token
+ -- TODO: perhaps a websocket instead?
+ :<|> "trip" :> "ping" :> ReqBody '[JSON] TripPing :> Post '[JSON] ()
+ -- debug things
+ :<|> "debug" :> "state" :> Get '[JSON] (Map Token [TripPing])
+type CompleteAPI = "debug" :> "openapi" :> Get '[JSON] Swagger
+ :<|> API