License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Swarm.Web
Contents
Description
A web service for Swarm.
The service can be started using the `--port 5357` command line argument,
or through the REPL by calling demoWeb
.
See SwarmAPI
for the available endpoints. You can also see them in your
browser on the top level endpoint:
lynx localhost:5357 -dump
or you can output the markdown documentation to your terminal:
cabal run swarm -O0 -- generate endpoints
Missing endpoints:
- TODO: #625 run endpoint to load definitions
- TODO: #493 export the whole game state
Synopsis
- startWebThread :: Maybe Port -> ReadableIORef AppState -> BChan AppEvent -> IO (Either String Port)
- defaultPort :: Port
- 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) :<|> (("recognize" :> ("log" :> Get '[JSON] [SearchLog EntityName])) :<|> (("recognize" :> ("found" :> Get '[JSON] [StructureLocation])) :<|> (("code" :> ("render" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("code" :> ("run" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("paths" :> ("log" :> Get '[JSON] (RingBuffer CacheLogEntry))) :<|> (("commands" :> Get '[JSON] CommandCatalog) :<|> (("repl" :> ("history" :> ("full" :> Get '[JSON] [REPLHistItem]))) :<|> ("map" :> (Capture "size" AreaDimensions :> Get '[JSON] GridResponse)))))))))))))))
- swarmApiHtml :: ByteString
- swarmApiMarkdown :: String
- webMain :: Maybe (MVar WebStartResult) -> Port -> ReadableIORef AppState -> BChan AppEvent -> IO ()
Documentation
Arguments
:: 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.
defaultPort :: Port Source #
Docs
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) :<|> (("recognize" :> ("log" :> Get '[JSON] [SearchLog EntityName])) :<|> (("recognize" :> ("found" :> Get '[JSON] [StructureLocation])) :<|> (("code" :> ("render" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("code" :> ("run" :> (ReqBody '[PlainText] Text :> Post '[PlainText] Text))) :<|> (("paths" :> ("log" :> Get '[JSON] (RingBuffer CacheLogEntry))) :<|> (("commands" :> Get '[JSON] CommandCatalog) :<|> (("repl" :> ("history" :> ("full" :> Get '[JSON] [REPLHistItem]))) :<|> ("map" :> (Capture "size" AreaDimensions :> Get '[JSON] GridResponse))))))))))))))) Source #
Development
Orphan instances
FromHttpApiData AreaDimensions Source # | |
Methods parseUrlPiece :: Text -> Either Text AreaDimensions # parseHeader :: ByteString -> Either Text AreaDimensions # parseQueryParam :: Text -> Either Text AreaDimensions # | |
ToSample AreaDimensions Source # | |
ToSample Text Source # | |
ToCapture (Capture "size" AreaDimensions) Source # | |
Methods toCapture :: Proxy (Capture "size" AreaDimensions) -> DocCapture # |