1
votes

I swear I saw this in the docs some time ago, but I can't seem to locate it now. Basically I'm looking for the equivalent of a rake routes command in servant, which prints out all routes in a human readable format.

1
Are you after routerLayout (see here) ? - Alp Mestanogullari
@AlpMestanogullari thank you! I have a feeling that this approach might be easier than stackoverflow.com/a/54890701/534481 to solve my actual problem. Btw, how does one go from Proxy api to Router env? Via this function - stackage.org/haddock/lts-12.1/servant-server-0.14.1/… ? Will passing an EmptyContext work, even if the app is actually using some Context (eg for basic-auth)? What about Delayed env (Server api)`? What does one pass here? (contd...) - Saurabh Nanda
@AlpMestanogullari (...contd) here's what I'm ultimately trying to do - I'm trying to "run the router" as an independent entity. I want to feed it a URL (or some variation thereof), eg. /posts/123 and get back a textual representation of the route it matched, eg. /posts/:id, or the Summary - stackage.org/haddock/lts-12.1/servant-0.14.1/… given in the route. - Saurabh Nanda

1 Answers

0
votes

Servant has a function layout that works on a proxy of the api, doesn't give you quite the same as rake routes, but it's the same information.

import Servant
import Data.Text.IO as T

type MyAPI = ...

printLayout = T.putStrLn $ layout (Proxy :: Proxy MyAPI)