【问题标题】:How to add a prefix to all the end points in Servant?如何为Servant中的所有端点添加前缀?
【发布时间】:2016-03-27 04:19:42
【问题描述】:

我在 Haskell 仆人中有一个 hello world 应用程序,这是其中的一部分:

type API = 
  "my_items" :> Get '[JSON] [MyItem]
  :<|> "my_items" :> Capture "id" Int :> Get '[JSON] MyItem
  -- ...................

网址是:

  localhost/my_items
  localhost/my_items/123

如何为现有网址和我将创建的其他网址添加前缀:

  localhost/api/v1/my_items
  localhost/api/v1/my_items/123
  localhost/api/v1/.....

?

【问题讨论】:

    标签: rest haskell servant


    【解决方案1】:

    只需创建另一种类型:

    type APIv1 = "api" :> "v1" :> API
    

    【讨论】:

      猜你喜欢
      • 2018-04-14
      • 2011-10-14
      • 2014-07-26
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多