3

Does anyone know any good rules of thumb, or good articles about organizing complex routes?

My Service has a routing that spans over about 400 lines, and IntelliJ is not the only one that has problems parsing and navigating it (also me).

What is a good way to split up the routing between multiple files, etc?

Ákos Vandra-Meyer
  • 1,890
  • 1
  • 23
  • 40
  • What have you tried so far? Have you tried to decompose your complex routes into a composition of smaller routes? For example you could have a separate route for each HTTP method (separate route for GET, separate route for PUT etc.), which could be simply combined using `~` method. – Paweł Jurczenko Jan 07 '17 at 15:07
  • Well I'd prefer having one responsibility per group, eg. cutting up based on route to have for ex. every operation on say users in one place, rather then by http methods. The main problem I am seeing is that I can't pas in the extracted session, etc. to these reoutes without making them into defs rather than vals. – Ákos Vandra-Meyer Jan 08 '17 at 10:29
  • 2
    Is having defs in this case would be a problem? All those defs (smaller, parametrized routes) would be invoked only once - during their combination into a complex route (which would be a `val`). – Paweł Jurczenko Jan 08 '17 at 12:04
  • 2
    A `Route` is a just a type alias for `RequestContext => Future[RouteResult]`, therefore you could compose it from smaller sub parts the same way you do function composition throughout the rest of scala. – Ramón J Romero y Vigil Jan 08 '17 at 12:11

0 Answers0