{"id":16651964,"url":"https://github.com/jdcasey/vabr","last_synced_at":"2025-08-11T16:06:21.029Z","repository":{"id":11025802,"uuid":"13356570","full_name":"jdcasey/vabr","owner":"jdcasey","description":"Vert.x Annotation-Based Routing (for the Java API)","archived":false,"fork":false,"pushed_at":"2015-02-18T00:00:24.000Z","size":808,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T12:58:11.836Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdcasey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-06T03:23:25.000Z","updated_at":"2022-07-13T11:21:24.000Z","dependencies_parsed_at":"2022-08-30T15:52:00.131Z","dependency_job_id":null,"html_url":"https://github.com/jdcasey/vabr","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdcasey%2Fvabr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdcasey%2Fvabr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdcasey%2Fvabr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdcasey%2Fvabr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdcasey","download_url":"https://codeload.github.com/jdcasey/vabr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243248114,"owners_count":20260748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T09:27:10.907Z","updated_at":"2025-03-12T15:43:01.556Z","avatar_url":"https://github.com/jdcasey.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vert.x Annotation-Based Routing\n\nThis is a relatively simple API and Java annotation processor that generates a Java source file containing routing object instances. Each instance corresponds to a different route, expressed using a path pattern (which may contain regular expressions) and a couple of other options. These instances basically delegate the call to the method that declared them.\n\n**NOTE:** To see this API in action, check out the [Freeki](https://github.com/jdcasey/freeki) project.\n\n## Step 1: Annotate\n\nSo, if you have a Java class that looks like this:\n\n```java\npackage org.foo.myapp;\n\nimport org.commonjava.vertx.vabr.Method;\nimport org.commonjava.vertx.vabr.RouteHandler;\nimport org.commonjava.vertx.vabr.anno.Route;\nimport org.commonjava.vertx.vabr.anno.Routes;\n\npublic class TemplateContentHandler\n    implements RouteHandler\n{\n\n    /* @formatter:off */\n    @Routes( {\n        @Route( path=\"/templates/:template\", method=Method.GET )\n    } )\n    /* @formatter:on */\n    public void get( final HttpServerRequest req )\n        throws Exception\n    {\n        final String template = req.params().get( \"template\" );\n        \n        final File html = controller.getTemplateHtml( template );\n        if ( !html.exists() )\n        {\n            req.response()\n               .setStatusCode( 404 )\n               .setStatusMessage( \"Not Found\" )\n               .end();\n        }\n        else\n        {\n            req.response()\n               .setStatusCode( 200 )\n               .sendFile( html.getAbsolutePath() );\n        }\n    }\n\n    private final TemplateController controller;\n    \n    private final JsonSerializer serializer;\n    \n    public TemplateContentHandler( final TemplateController controller, final JsonSerializer serializer )\n    {\n        this.controller = controller;\n        this.serializer = serializer;\n    }\n}\n```\n\n## Step 2: Generate\n\nThe Apache Maven POM configuration will look similar to this:\n\n```xml\n\u003cproperties\u003e\n  \u003cvabrVersion\u003e1.1\u003c/vabrVersion\u003e\n\u003c/properties\u003e\n\n\u003cdependencies\u003e\n  [...]\n\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.commonjava.vertx\u003c/groupId\u003e\n    \u003cartifactId\u003evabr-api\u003c/artifactId\u003e\n    \u003cversion\u003e${vabrVersion}\u003c/version\u003e\n  \u003c/dependency\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.commonjava.vertx\u003c/groupId\u003e\n    \u003cartifactId\u003evabr-processor\u003c/artifactId\u003e\n    \u003cversion\u003e${vabrVersion}\u003c/version\u003e\n    \u003cscope\u003eprovided\u003c/scope\u003e\n  \u003c/dependency\u003e\n\u003c/dependencies\u003e\n\n\u003cbuild\u003e\n  [...]\n\n  \u003cpluginManagement\u003e\n    \u003cplugins\u003e\n      \u003cplugin\u003e\n        \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e3.1\u003c/version\u003e\n        \u003cconfiguration\u003e\n          \u003csource\u003e1.7\u003c/source\u003e\n          \u003ctarget\u003e1.7\u003c/target\u003e\n          \u003cannotationProcessors\u003e\n            \u003cannotationProcessor\u003eorg.commonjava.vertx.vabr.anno.proc.RoutingAnnotationProcessor\u003c/annotationProcessor\u003e\n          \u003c/annotationProcessors\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n    \n      [...]\n    \u003c/plugins\u003e\n  \u003c/pluginManagement\u003e\n  [...]\n\u003c/build\u003e\n```\n\nThe annotation processor will generate the following Java:\n\n```java\npackage org.foo.myapp;\n\nimport org.commonjava.vertx.vabr.ApplicationRouter;\nimport org.commonjava.vertx.vabr.RouteBinding;\nimport org.commonjava.vertx.vabr.Method;\nimport org.commonjava.vertx.vabr.AbstractRouteCollection;\n\nimport org.vertx.java.core.http.HttpServerRequest;\n\nimport org.commonjava.util.logging.Logger;\n\npublic final class Routes\n    extends AbstractRouteCollection\n{\n  \n    private final Logger logger = new Logger( getClass() );\n    \n    public Routes()\n    {\n        bind( new RouteBinding( \"/templates/:template\", Method.GET, \"\" )\n        {\n            public void dispatch( ApplicationRouter router, HttpServerRequest req )\n                throws Exception\n            {\n                org.foo.myapp.TemplateContentHandler handler = router.getResourceInstance( org.foo.myapp.TemplateContentHandler.class );\n                if ( handler != null )\n                {\n                    logger.debug( \"Handling via: %s\", handler );\n                    handler.get( req );\n                }\n                else\n                {\n                    throw new RuntimeException( \"Cannot retrieve handler instance for: '/templates/:template' using method: 'GET'\" );\n                } \n            }\n        } );\n    }\n}\n```\n\n## Step 3: Launch!\n\nTo initialize the controller that knows how to handle these generated route bindings, use something like the following:\n\n```java\nfinal Set\u003cRouteHandler\u003e handlers = Collections.singleton( new TemplateContentHandler( new TemplateController( store, config ), serializer ) );\n\nfinal ServiceLoader\u003cRouteCollection\u003e collections = ServiceLoader.load( RouteCollection.class );\n\nfinal ApplicationRouter router = new ApplicationRouter( handlers, collections );\n\nvertx.createHttpServer()\n     .requestHandler( router )\n     .listen( 8080, \"127.0.0.1\" );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdcasey%2Fvabr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdcasey%2Fvabr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdcasey%2Fvabr/lists"}