{"id":26560700,"url":"https://github.com/robothy/netty-http-router","last_synced_at":"2026-05-11T02:21:56.834Z","repository":{"id":43028215,"uuid":"510296599","full_name":"Robothy/netty-http-router","owner":"Robothy","description":"a Netty HTTP router library.","archived":false,"fork":false,"pushed_at":"2023-07-31T05:45:33.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-07-31T06:35:19.914Z","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/Robothy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-04T09:36:09.000Z","updated_at":"2023-07-31T06:35:19.915Z","dependencies_parsed_at":"2023-01-26T13:16:45.428Z","dependency_job_id":null,"html_url":"https://github.com/Robothy/netty-http-router","commit_stats":null,"previous_names":[],"tags_count":16,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robothy%2Fnetty-http-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robothy%2Fnetty-http-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robothy%2Fnetty-http-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Robothy%2Fnetty-http-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Robothy","download_url":"https://codeload.github.com/Robothy/netty-http-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244959665,"owners_count":20538672,"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":"2025-03-22T13:19:51.026Z","updated_at":"2026-05-11T02:21:56.774Z","avatar_url":"https://github.com/Robothy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# netty-http-router\n\n[![Build](https://github.com/Robothy/netty-http-router/actions/workflows/push.yml/badge.svg)](https://github.com/Robothy/netty-http-router/actions/workflows/push.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.robothy/netty-http-router?color=blueviolet\u0026logo=apachemaven)](https://central.sonatype.dev/artifact/io.github.robothy/netty-http-router/1.13/versions)\n\nA library help to build web applications based on Netty.\n\n## 1. Getting Started\n\n### Dependency\n\nThis library is published to the Maven Central, you can add this dependency without extra configurations.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.robothy\u003c/groupId\u003e\n    \u003cartifactId\u003enetty-http-router\u003c/artifactId\u003e\n    \u003cversion\u003e1.13\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### 1.3 Hello World\n\nThe HelloWord example follows the standard steps of startup a Netty application. You only\nneed to define a `Router` and an executor group that executes HTTP message handlers.\n\n```java\nclass HelloWorld {\n  public static void main(String[] args) throws InterruptedException {\n    Router router = Router.router()\n        .route(HttpMethod.GET, \"/hello\", ((request, response) -\u003e response\n            .status(HttpResponseStatus.OK)\n            .write(\"Hello World\")));\n\n    DefaultEventExecutorGroup executor = new DefaultEventExecutorGroup(2);\n    HttpServerInitializer serverInitializer = new HttpServerInitializer(executor, router);\n\n    EventLoopGroup parentGroup = new NioEventLoopGroup(1);\n    EventLoopGroup childGroup = new NioEventLoopGroup(1);\n    Channel serverSocketChannel = new ServerBootstrap().group(parentGroup, childGroup)\n        .handler(new LoggingHandler(LogLevel.DEBUG))\n        .channel(NioServerSocketChannel.class)\n        .childHandler(serverInitializer)\n        .bind(8686)\n        .sync()\n        .channel();\n    serverSocketChannel.close().sync();\n  }\n}\n```\n\n## 2. Usages\n\n### 2.1 Request mapping\n\nnetty-http-router map an HTTP request to a `HttpMessageHandler` according to the method, path, headers, and query parameters.\n\n#### Request path pattern\n\nThis library uses SpringMVC path pattern to match request paths.\n\n+ `\"/hello\"` matches `\"/hello\"`\n+ `\"/user/{id}\"` matches `'/user/123'`, `/user/666`, etc.\n+ `/user/{id}/profile` matches `/user/123/profile`, `/user/bob/profie`, etc.\n+ `/user/{id:[0-9]{1,}}/profile` matches `/user/123/profile` and not match `/user/bob/profile`.\n\nYou can find more details about the path pattern in the [PathPattern](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/pattern/PathPattern.html) javadoc.\n\n#### Headers and parameters matcher\n\nnetty-http-router allows setting headers and parameters match rules via \n`headerMatcher(header rule)` and `paramMatcher(parameter rule)`. The matching\npriority from high to low is HTTP method, path, headers, and parameters.\n\n```java\nRoute.builder()\n    .method(HttpMethod.HEAD)\n    .path(\"/a/content\")\n    .headerMatcher(headers -\u003e headers.containsKey(\"X-Authorization\"))\n    .paramsMatcher(params -\u003e params.containsKey(\"user\"))\n    .handler(paramRequestHandler)\n    .build()\n```\n\n### 2.2 Serving static resources\n\nnetty-http-router scans static resources in the `/static` directory of the classpath by default.\nYou can customize the path via `Router#staticResources()`.\n\n```java\nRouter router=Router.router()\n    .route(HttpMethod.GET,\"/\", handler)\n    .staticResource(\"my-static-resources\");\n```\n\n### 2.3 Not found handler and exception handlers\n\nYou can set a not found handler and exception handlers for a Router.\n\n```java\nRouter router=Router.router()\n    .route(HttpMethod.GET,\"/\", handler)\n    .notFound((request, response) -\u003e response.status(HttpResponseStatus.NOT_FOUND))\n    .exceptionHandler(IllegalArgumentException.class, (e, request, response) -\u003e response\n      .status(HttpResponseStatus.BAD_REQUEST)\n      .write(e.getMessage()))\n    .exceptionHandler(IllegalStateException.class, (e, request, response) -\u003e response\n      .status(HttpResponseStatus.INTERNAL_SERVER_ERROR)\n      .write(e.getMessage()))\n    ;\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobothy%2Fnetty-http-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobothy%2Fnetty-http-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobothy%2Fnetty-http-router/lists"}