License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A web service for Swarm.
The service can be started using the `--port 5357` command line argument,
or through the REPL by calling demoWeb
.
Once running, here are the available endpoints:
- /robots : return the list of robots
- robotID : return a single robot identified by its id
Missing endpoints:
- TODO: #625 run endpoint to load definitions
- TODO: #493 export the whole game state
Synopsis
- newtype RobotID = RobotID Int
- type SwarmAPI = ("robots" :> Get '[JSON] [Robot]) :<|> (("robot" :> (Capture "id" RobotID :> Get '[JSON] (Maybe Robot))) :<|> (("goals" :> ("prereqs" :> Get '[JSON] [PrereqSatisfaction])) :<|> (("goals" :> ("active" :> Get '[JSON] [Objective])) :<|> (("goals" :> ("graph" :> Get '[JSON] (Maybe GraphInfo))) :<|> (("goals" :> ("uigoal" :> Get '[JSON] GoalTracking)) :<|> (("goals" :> Get '[JSON] WinCondition) :<|> (("code" :> ("render" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("code" :> ("run" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> ("repl" :> ("history" :> ("full" :> Get '[JSON] [REPLHistItem])))))))))))
- swarmApi :: Proxy SwarmAPI
- type ToplevelAPI = SwarmAPI :<|> Raw
- api :: Proxy ToplevelAPI
- docsBS :: ByteString
- mkApp :: ReadableIORef AppState -> BChan AppEvent -> Server SwarmAPI
- data WebStartResult
- webMain :: Maybe (MVar WebStartResult) -> Port -> ReadableIORef AppState -> BChan AppEvent -> IO ()
- defaultPort :: Port
- startWebThread :: Maybe Port -> ReadableIORef AppState -> BChan AppEvent -> IO (Either String Port)
Documentation
type SwarmAPI = ("robots" :> Get '[JSON] [Robot]) :<|> (("robot" :> (Capture "id" RobotID :> Get '[JSON] (Maybe Robot))) :<|> (("goals" :> ("prereqs" :> Get '[JSON] [PrereqSatisfaction])) :<|> (("goals" :> ("active" :> Get '[JSON] [Objective])) :<|> (("goals" :> ("graph" :> Get '[JSON] (Maybe GraphInfo))) :<|> (("goals" :> ("uigoal" :> Get '[JSON] GoalTracking)) :<|> (("goals" :> Get '[JSON] WinCondition) :<|> (("code" :> ("render" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("code" :> ("run" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> ("repl" :> ("history" :> ("full" :> Get '[JSON] [REPLHistItem]))))))))))) Source #
api :: Proxy ToplevelAPI Source #
docsBS :: ByteString Source #
data WebStartResult Source #
Simple result type to report errors from forked startup thread.
:: Maybe (MVar WebStartResult) | |
-> Port | |
-> ReadableIORef AppState | |
-> BChan AppEvent | Writable |
-> IO () |
defaultPort :: Port Source #
:: Maybe Port | |
-> ReadableIORef AppState | Read-only reference to the application state. |
-> BChan AppEvent | Writable channel to send events to the game |
-> IO (Either String Port) |
Attempt to start a web thread on the requested port, or a default
one if none is requested (or don't start a web thread if the
requested port is 0). If an explicit port was requested, fail if
startup doesn't work. Otherwise, ignore the failure. In any
case, return a Maybe Port
value representing whether a web
server is actually running, and if so, what port it is on.