首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在带有Servant的内部Api前添加公共根路径

在带有Servant的内部Api前添加公共根路径
EN

Stack Overflow用户
提问于 2018-12-13 23:22:01
回答 1查看 79关注 0票数 0

我有以下接口:

代码语言:javascript
复制
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中一次?

附言:佣人做得好得令人惊讶!

EN

回答 1

Stack Overflow用户

发布于 2018-12-13 23:48:26

可以,合并后可以将前缀添加到两个分支中:

代码语言:javascript
复制
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在某种程度上解决了这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53765021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档