Routing
route
s are agnostic to what router is used upstream. Since routes are standlone, we have many options for handling routing.
Filesystem Routing
Webroute shines in filesystem router contexts, where middleware is either unavailable or especially awkward. Additionally, route
s are very lightweight, only loading the necessary code for each route invocation.
webroute
works idiomatically with filesystem routers.
@webroute/router
We can use route
s with @webroute/router
by registering routes.
Or if we have many routes, we can use the normalizeRoutes
method.
Learn more about the Router package.
No Routing
In smaller projects this approach is sufficient. However, as the number of routes or path complexity increases, you'll likely want to use a more sophisticated routing approach.
In many cases, you don't actually need a fancy router at all. It's completely valid to export a single route and call it a day.
The Route.getPath
and Route.getMethods
helpers, found on the route
export, are helpful for building custom routing.
Third Party Frameworks
In more sophisticated apps, or if integrating with an existing app, we may wish to use an external router/framework.
One-by-one
In the most basic case, we can simply wire up our routes explicitly and manually.
Many at Once
We can also perform this iteratively when we have quite a few routes.
Bear in mind most external routers care about route registration order.
What about adapters?
As we've seen above, connecting our routes to existing apps is fairly straightforward: merely register the apps path and method(s) with the route itself. Instead of providing and maintaining adapters, we think it's more robust to leave that up to the developer.
Ultimately, by writing your own "adapter" code, you will retain greater control, with pretty minimal work.
More guidance on integrating with existing frameworks and apps can be found in the Building Apps section.