I'm using Servant generic, and have a datatype for my routes:
data Routes route = Routes
{ getLiveness :: route :- GetLiveness,
getReadiness :: route :- GetReadiness,
getAuthVerifyEmailToken :: route :- GetAuthVerifyEmailToken,
postAuthEmail :: route :- PostAuthEmail,
...
}
deriving (Generic)
type BackendPrefix = "backend"
type AuthPrefix = "auth"
type GetLiveness = BackendPrefix :> "liveness" :> Get '[JSON] Text
type GetReadiness = BackendPrefix :> "readiness" :> Get '[JSON] Text
type GetAuthVerifyEmailToken = AuthPrefix :> "verify" :> "email" :> Capture "token" JWT :> RedirectResponse '[PlainText] NoContent
type PostAuthEmail = AuthPrefix :> "email" :> ReqBody '[JSON] AuthEmailRequest :> PostNoContent
The first two use the same prefix "backend"
, and all other's have an "auth"
prefix.
However, I now want to change the "auth
" prefix to "backend/auth". So I tried chaging:
type AuthPrefix = BackendPrefix :> "auth"
This results in an error
> • Expected a type, but
> ‘"auth"’ has kind
> ‘ghc-prim-0.6.1:GHC.Types.Symbol’
> • In the second argument of ‘(:>)’, namely ‘"auth"’
> In the type ‘BackendPrefix :> "auth"’
> In the type declaration for ‘AuthPrefix’
> |
> 34 | type AuthPrefix = BackendPrefix :> "auth"
> |
So I googled and found you can do this when not using generic you can do:
type APIv1 = "api" :> "v1" :> API
But I couldn't figure out how to do this with generics.
I guess that leaves two questions:
- What does the above error mean, and can I use something like
type AuthPrefix = BackendPrefix :> "auth"
to create a more complex prefix? - Is there a way to prefix some routes with one prefix, and the other routes with a different prefix, when using generics in Servant?