4949 * <h1>Starting a new application:</h1>
5050 * <p>
5151 * A new application must extends Jooby, choose a server implementation, register one ore more
52- * {@link BodyConverter} and defines some {@link Route routes}. It sounds like a lot of work to do,
52+ * {@link BodyConverter} and defines some {@link Router routes}. It sounds like a lot of work to do,
5353 * but it isn't.
5454 * </p>
5555 *
276276 * @see Request
277277 * @see Response
278278 * @see BodyConverter
279- * @see Route
279+ * @see Router
280280 * @see RouteInterceptor
281281 * @see RequestModule
282282 */
@@ -314,6 +314,14 @@ public class Jooby {
314314 /** Keep the global injector instance. */
315315 private Injector injector ;
316316
317+ public RouteDefinition use (final Filter filter ) {
318+ return use ("/**" , filter );
319+ }
320+
321+ public RouteDefinition use (final String path , final Filter filter ) {
322+ return route (new RouteDefinitionImpl ("*" , path , filter ));
323+ }
324+
317325 /**
318326 * Define an in-line route that supports HTTP GET method:
319327 *
@@ -329,33 +337,12 @@ public class Jooby {
329337 * @param route A route to execute. Required.
330338 * @return A new route definition.
331339 */
332- public RouteDefinition get (final String path , final Route route ) {
340+ public RouteDefinition get (final String path , final Router route ) {
333341 return route (new RouteDefinitionImpl ("GET" , path , route ));
334342 }
335343
336- /**
337- * Define an external route that supports HTTP GET method:
338- *
339- * <pre>
340- * get("/", MyRoute.class);
341- *
342- * // MyRoute.java
343- * public class MyRoute implements Route {
344- * public void handle(Request request, Response response) {
345- * response.send(something);
346- * }
347- * }
348- * </pre>
349- *
350- * An external route is created per-request. They aren't singleton.
351- *
352- * @param path A route path. Required.
353- * @param route A route to execute. Required.
354- * @return A new route definition.
355- * @see RequestModule
356- */
357- public RouteDefinition get (final String path , final Class <? extends Route > route ) {
358- return route (new RouteDefinitionImpl ("GET" , path , wrapRoute (route )));
344+ public RouteDefinition get (final String path , final Filter filter ) {
345+ return route (new RouteDefinitionImpl ("GET" , path , filter ));
359346 }
360347
361348 /**
@@ -373,33 +360,12 @@ public RouteDefinition get(final String path, final Class<? extends Route> route
373360 * @param route A route to execute. Required.
374361 * @return A new route definition.
375362 */
376- public RouteDefinition post (final String path , final Route route ) {
363+ public RouteDefinition post (final String path , final Router route ) {
377364 return route (new RouteDefinitionImpl ("POST" , path , route ));
378365 }
379366
380- /**
381- * Define an external route that supports HTTP POST method:
382- *
383- * <pre>
384- * post("/", MyRoute.class);
385- *
386- * // MyRoute.java
387- * public class MyRoute implements Route {
388- * public void handle(Request request, Response response) {
389- * response.send(something);
390- * }
391- * }
392- * </pre>
393- *
394- * An external route is created per-request. They aren't singleton.
395- *
396- * @param path A route path. Required.
397- * @param route A route to execute. Required.
398- * @return A new route definition.
399- * @see RequestModule
400- */
401- public RouteDefinition post (final String path , final Class <? extends Route > route ) {
402- return route (new RouteDefinitionImpl ("POST" , path , wrapRoute (route )));
367+ public RouteDefinition post (final String path , final Filter filter ) {
368+ return route (new RouteDefinitionImpl ("POST" , path , filter ));
403369 }
404370
405371 /**
@@ -417,33 +383,12 @@ public RouteDefinition post(final String path, final Class<? extends Route> rout
417383 * @param route A route to execute. Required.
418384 * @return A new route definition.
419385 */
420- public RouteDefinition put (final String path , final Route route ) {
386+ public RouteDefinition put (final String path , final Router route ) {
421387 return route (new RouteDefinitionImpl ("PUT" , path , route ));
422388 }
423389
424- /**
425- * Define an external route that supports HTTP PUT method:
426- *
427- * <pre>
428- * put("/", MyRoute.class);
429- *
430- * // MyRoute.java
431- * public class MyRoute implements Route {
432- * public void handle(Request request, Response response) {
433- * response.send(something);
434- * }
435- * }
436- * </pre>
437- *
438- * An external route is created per-request. They aren't singleton.
439- *
440- * @param path A route path. Required.
441- * @param route A route to execute. Required.
442- * @return A new route definition.
443- * @see RequestModule
444- */
445- public RouteDefinition put (final String path , final Class <? extends Route > route ) {
446- return route (new RouteDefinitionImpl ("PUT" , path , wrapRoute (route )));
390+ public RouteDefinition put (final String path , final Filter filter ) {
391+ return route (new RouteDefinitionImpl ("PUT" , path , filter ));
447392 }
448393
449394 /**
@@ -458,36 +403,15 @@ public RouteDefinition put(final String path, final Class<? extends Route> route
458403 * This is a singleton route so make sure you don't share or use global variables.
459404 *
460405 * @param path A route path. Required.
461- * @param route A route to execute. Required.
406+ * @param router A route to execute. Required.
462407 * @return A new route definition.
463408 */
464- public RouteDefinition delete (final String path , final Route route ) {
465- return route (new RouteDefinitionImpl ("DELETE" , path , route ));
409+ public RouteDefinition delete (final String path , final Router router ) {
410+ return route (new RouteDefinitionImpl ("DELETE" , path , router ));
466411 }
467412
468- /**
469- * Define an external route that supports HTTP DELETE method:
470- *
471- * <pre>
472- * delete("/", MyRoute.class);
473- *
474- * // MyRoute.java
475- * public class MyRoute implements Route {
476- * public void handle(Request request, Response response) {
477- * response.send(something);
478- * }
479- * }
480- * </pre>
481- *
482- * An external route is created per-request. They aren't singleton.
483- *
484- * @param path A route path. Required.
485- * @param route A route to execute. Required.
486- * @return A new route definition.
487- * @see RequestModule
488- */
489- public RouteDefinition delete (final String path , final Class <? extends Route > route ) {
490- return route (new RouteDefinitionImpl ("DELETE" , path , wrapRoute (route )));
413+ public RouteDefinition delete (final String path , final Filter filter ) {
414+ return route (new RouteDefinitionImpl ("DELETE" , path , filter ));
491415 }
492416
493417 /**
@@ -496,7 +420,7 @@ public RouteDefinition delete(final String path, final Class<? extends Route> ro
496420 * @param route The external route class.
497421 * @return A new inline route.
498422 */
499- private static Route wrapRoute (final Class <? extends Route > route ) {
423+ private static Router wrapRouter (final Class <? extends Router > route ) {
500424 return (req , resp ) -> req .getInstance (route ).handle (req , resp );
501425 }
502426
@@ -514,7 +438,7 @@ private static Route wrapRoute(final Class<? extends Route> route) {
514438 * @return A new route definition.
515439 */
516440 public RouteDefinition assets (final String path ) {
517- return get (path , AssetRoute .class );
441+ return get (path , wrapRouter ( AssetRoute .class ) );
518442 }
519443
520444 /**
@@ -669,9 +593,6 @@ public void configure(final Binder binder) {
669593 requestModule .addBinding ().toInstance (
670594 rm -> protoRoutes .forEach (routeClass -> rm .bind (routeClass )));
671595
672- // Route Interceptors
673- Multibinder .newSetBinder (binder , RouteInterceptor .class );
674-
675596 // tmp dir
676597 binder .bind (File .class ).annotatedWith (Names .named ("java.io.tmpdir" ))
677598 .toInstance (new File (config .getString ("java.io.tmpdir" )));
0 commit comments