1

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.

Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
  • Are you after `routerLayout` (see [here](https://hackage.haskell.org/package/servant-server-0.16/docs/Servant-Server-Internal-Router.html#v:routerLayout)) ? – Alp Mestanogullari Apr 03 '19 at 14:52
  • @AlpMestanogullari thank you! I have a feeling that this approach might be easier than https://stackoverflow.com/a/54890701/534481 to solve my actual problem. Btw, how does one go from `Proxy api` to `Router env`? Via this function - https://www.stackage.org/haddock/lts-12.1/servant-server-0.14.1/Servant-Server-Internal.html#v:route ? 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 Apr 04 '19 at 05:58
  • @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` - https://www.stackage.org/haddock/lts-12.1/servant-0.14.1/Servant-API.html#t:Summary given in the route. – Saurabh Nanda Apr 04 '19 at 06:01

1 Answers1

0

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)
francisco
  • 1
  • 1