我有以下API:
type GSDMonitoringApi = FetchWorkspaceIdsCreated
:<|> FetchGsdCommandsByWorkspaceId
type FetchWorkspaceIdsCreated = "gsd" :> "monitoring" :> "workspaceIds" :> Get '[JSON] [Persisted WorkspaceId]
type FetchGsdCommandsByWorkspaceId = "gsd" :> "monitoring" :> "commands" :> Capture "workspaceId" WorkspaceId :> Get '[JSON] [Persisted GsdCommand]
是否可以排除"gsd" :> "monitoring" :>
并将其放入GSDMonitoringApi一次?
P.S:仆人做得好极了!
答案 0 :(得分:1)
是的,您可以在合并两个分支后将前缀添加到这两个分支:
type GSDMonitoringApi =
"gsd" :> "monitoring" :>
( FetchWorkspaceIdsCreated :<|> FetchGsdCommandsByWorkspaceId )
type FetchWorkspaceIdsCreated = "workspaceIds" :> Get '[JSON] [Persisted WorkspaceId]
type FetchGsdCommandsByWorkspaceId = "commands" :> Capture "workspaceId" WorkspaceId :> Get '[JSON] [Persisted GsdCommand]
作为半关联点,我建议您签出Servant.API.Generic
。像这样将API与:<|>
组合在一起非常难看。 Servant.API.Generic
在某种程度上解决了这个问题。