How to add a prefix to all endpoints in Servant?

I have a hello world application in Haskell servant, here is part of it:

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

and URL:

  localhost/my_items
  localhost/my_items/123

How to add a prefix to existing URLs and others that I will create:

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

?

+4
source share
1 answer

Just create another type:

type APIv1 = "api" :> "v1" :> API
+7
source

All Articles