haskell - 在带有 Servant 的内部 Api 之前添加公共根路径
问题描述
我有以下 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 一次?
PS:仆人做的真好!
解决方案
是的,您可以在合并后将前缀添加到两个分支:
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
在一定程度上解决了这个问题。
推荐阅读
- java - Java Swing:当某个组件更新时,组件会自动改变位置
- java - Lombok builder,构建对象的一半,然后完成另一半的构建
- r - 如何在 ubuntu docker 镜像中静默安装 r-base
- python - xpath string() 从渲染中排除特定节点
- android - 如何在 Android tabLayout 的选项卡中将喜欢的重量更改为粗体?
- ajax - 在 asp 中将启用 wcf ajax 的文件添加到 Web 表单会产生验证错误
- javascript - 角度路由器导航在 IONIC4 中不起作用
- java - CardView.setRadius() 在以编程方式分配时不起作用
- virtualbox - 在 Virtual Box 上使用 Linux 作为主要工作区?
- sql - PL/SQL 循环遍历列表并查找数据库表中不存在的值