Search code examples
resthaskellservant

How to add a prefix to all the end points in Servant?


I have kind of a hello world app in Haskell servant, here's a part of it:

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

and the urls are:

  localhost/my_items
  localhost/my_items/123

How can I add a prefix to the existing urls and others I'll create:

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

?


Solution

  • Just create another type:

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