{"id":15684078,"url":"https://github.com/pmlopes/vertx-web-annotations","last_synced_at":"2025-05-07T15:08:00.827Z","repository":{"id":142726142,"uuid":"56767538","full_name":"pmlopes/vertx-web-annotations","owner":"pmlopes","description":null,"archived":false,"fork":false,"pushed_at":"2016-04-21T12:02:06.000Z","size":18,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T15:07:52.266Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmlopes.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-21T11:17:53.000Z","updated_at":"2024-04-12T12:04:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"36ada03d-bbcd-4b92-8c1b-5ae8c43936f2","html_url":"https://github.com/pmlopes/vertx-web-annotations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fvertx-web-annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fvertx-web-annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fvertx-web-annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmlopes%2Fvertx-web-annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmlopes","download_url":"https://codeload.github.com/pmlopes/vertx-web-annotations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902614,"owners_count":21822261,"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-03T17:10:50.839Z","updated_at":"2025-05-07T15:08:00.818Z","avatar_url":"https://github.com/pmlopes.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vert.x-Web Annotations\n\nThis is a basic annotation addon to Vert.x-Web in order to de-clutter your code.\n\nThere are annotations for all HTTP methods plus content negotiation.\n\n## Usage:\n\nInitially create a POJO and annotate the public methods with a RoutingContext as argument\nwith one of the annotations, e.g.: `GET`\n\n```java\npublic class TestRouter {\n  @GET(\"/ws\")\n  public void get(RoutingContext ctx) {\n    ctx.response().end(\"Hello ws!\");\n  }\n}\n```\n\nNow in your main Verticle you can transform this POJO to a router as:\n\n```java\npublic class MyVerticle extends AbstactVerticle {\n\n  @Override\n  public void start() {\n    final Router app = AnnotatedRouter.create(vertx, new TestRouter());\n\n    vertx.createHttpServer()\n      .requestHandler(app::accept)\n      .listen(8080);\n  }\n}\n```\n\nIf you want to compose your app from various POJOs, you can do it like:\n\n```java\npublic class MyVerticle extends AbstactVerticle {\n\n  @Override\n  public void start() {\n    Router app;\n\n    app = AnnotatedRouter.create(vertx, new SomePOJO());\n    // note that the first argument is now the previous Router\n    app = AnnotatedRouter.append(app, new OtherPOJO());\n\n    vertx.createHttpServer()\n      .requestHandler(app::accept)\n      .listen(8080);\n  }\n}\n```\n\nAlternatively you can specify all POJOs at once using a vararg param:\n\n```java\npublic class MyVerticle extends AbstactVerticle {\n\n  @Override\n  public void start() {\n    final Router app = AnnotatedRouter.create(vertx, new SomePOJO(), new OtherPOJO());\n\n    vertx.createHttpServer()\n      .requestHandler(app::accept)\n      .listen(8080);\n  }\n}\n```\n\n## Design decisions\n\nThe POJO to be passed to the builder is a Object instance not a class, the reason for this is that\nin some cases it is handy to have a constructor where you can pass arguments such as configuration,\nvertx instance, etc....\n\n\n## Extending this thing!\n\nSo you want more annotations, perhaps you want swagger generation ;) well in that case all you need\nis to:\n\n1. Create your custom annotation\n2. Register a new processor for your annotation\n3. Profit\n\n### Example\n\n#### Create a custom annotation\n\n```java\n@Retention(RetentionPolicy.RUNTIME)\n@Target({ElementType.METHOD})\npublic @interface Say {\n  String value() default \"Hello World\";\n}\n```\n\n#### Create a processor\n\n```java\npublic class SayProcessorHandler extends AbstractAnnotationHandler\u003cRouter\u003e {\n\n  public SayProcessorHandler() {\n    super(Router.class);\n  }\n\n  @Override\n  public void process(final Router router, final Object instance, final Class\u003c?\u003e clazz, final Method method) {\n\n    if (Processor.isCompatible(method, Say.class, RoutingContext.class)) {\n      System.out.println(\"The annotation says: \" + Processor.getAnnotation(method, Say.class).value());\n    }\n  }\n}\n```\n\nAs you see from the process method, you have the router object instance and your annotation so now\nyou can add your custom handlers if you wish so, e.g.:\n\n```java\npublic class SayProcessorHandler extends AbstractAnnotationHandler\u003cRouter\u003e {\n\n  public SayProcessorHandler() {\n    super(Router.class);\n  }\n\n  @Override\n  public void process(final Router router, final Object instance, final Class\u003c?\u003e clazz, final Method method) {\n\n    if (Processor.isCompatible(method, Say.class, RoutingContext.class)) {\n      final String whatToSay = Processor.getAnnotation(method, Say.class).value();\n      router.route().handler(ctx -\u003e {\n        System.out.println(whatToSay);\n        ctx.next();\n      });\n    }\n  }\n}\n```\n\n#### Register a custom processor\n\n```java\nProcessor.registerProcessor(SayProcessorHandler.class);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmlopes%2Fvertx-web-annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmlopes%2Fvertx-web-annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmlopes%2Fvertx-web-annotations/lists"}