{"id":13694828,"url":"https://github.com/pyloque/httpkids","last_synced_at":"2026-02-13T05:54:38.332Z","repository":{"id":151075846,"uuid":"130811966","full_name":"pyloque/httpkids","owner":"pyloque","description":"http server based on netty for kids","archived":false,"fork":false,"pushed_at":"2018-05-15T06:27:28.000Z","size":108,"stargazers_count":162,"open_issues_count":0,"forks_count":59,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-12T21:39:20.946Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyloque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-24T07:11:16.000Z","updated_at":"2024-11-09T11:58:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5ea8d6a-78dc-4047-803c-44afff392ec3","html_url":"https://github.com/pyloque/httpkids","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyloque%2Fhttpkids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyloque%2Fhttpkids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyloque%2Fhttpkids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyloque%2Fhttpkids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyloque","download_url":"https://codeload.github.com/pyloque/httpkids/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252144521,"owners_count":21701427,"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-08-02T17:01:44.267Z","updated_at":"2026-02-13T05:54:38.286Z","avatar_url":"https://github.com/pyloque.png","language":"Java","funding_links":[],"categories":["Java","网络编程"],"sub_categories":["Spring Cloud框架"],"readme":"httpkids\n--\nWeb framework based on netty for kids, java10 required!\n\nFeatures \u0026 Disadvantages\n--\n1. Extremely lightweight compared with other web frameworks.\n2. Extremely easy to use, Extermly low cost for learning.\n3. Extremely easy to understand, With approximately 1200 lines of code.\n4. No support for https yet.\n5. No support for URL with restful style.\n\nHelloWorld\n--\n```java\nimport httpkids.server.KidsRequestDispatcher;\nimport httpkids.server.Router;\nimport httpkids.server.internal.HttpServer;\n\npublic class HelloWorld {\n\n    public static void main(String[] args) {\n        var rd = new KidsRequestDispatcher(\"/kids\", new Router((ctx, req) -\u003e {\n            ctx.html(\"Hello, World\");\n        }));\n        new HttpServer(\"localhost\", 8080, 2, 16, rd).start();\n    }\n\n}\n\nhttp://localhost:8080/kids\n```\n\n\nFullStack\n--\n```java\nimport java.util.HashMap;\n\nimport httpkids.server.KidsRequestDispatcher;\nimport httpkids.server.Router;\nimport httpkids.server.internal.HttpServer;\n\npublic class HelloWorld {\n\n\tpublic static void main(String[] args) {\n\t\tvar router = new Router((ctx, req) -\u003e {\n\t\t\tctx.html(\"Hello, World\");  // 纯文本html\n\t\t})\n\t\t.handler(\"/hello.json\", (ctx, req) -\u003e {\n\t\t\tctx.json(new String[] { \"Hello\", \"World\" });  // JSON API\n\t\t})\n\t\t.handler(\"/hello\", (ctx, req) -\u003e {\n\t\t\tvar res = new HashMap\u003cString, Object\u003e();\n\t\t\tres.put(\"req\", req);\n\t\t\tctx.render(\"playground.ftl\", res); // 模版渲染\n\t\t})\n\t\t.handler(\"/world\", (ctx, req) -\u003e {\n\t\t\tctx.redirect(\"/hello\");  // 302跳转\n\t\t})\n\t\t.handler(\"/error\", (ctx, req) -\u003e {\n\t\t\tctx.abort(500, \"wtf\");  // 异常\n\t\t})\n\t\t.resource(\"/pub\", \"/static\")  // 静态资源\n\t\t.child(\"/user\", () -\u003e {  // 路由嵌套\n\t\t\treturn new Router((ctx, req) -\u003e {\n\t\t\t\tctx.html(\"Hello, World\");\n\t\t\t})\n\t\t\t.handler(\"/hello.json\", (ctx, req) -\u003e {\n\t\t\t\tctx.json(new String[] { \"Hello\", \"World\" });\n\t\t\t})\n\t\t\t.filter((ctx, req, before) -\u003e {  // 过滤器、拦截器\n\t\t\t\tif (before) {\n\t\t\t\t\tSystem.out.printf(\"before %s\\n\", req.path());\n\t\t\t\t} else {\n\t\t\t\t\tSystem.out.printf(\"after %s\\n\", req.path());\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t});\n\t\t});\n\n\t\tvar rd = new KidsRequestDispatcher(\"/kids\", router); // 请求派发器\n\t\trd.templateRoot(\"/tpl\"); // 模版classpath根目录\n\t\trd.exception(500, (ctx, e) -\u003e { // 异常处理\n\t\t\tctx.html(\"what the fuck it is\", 500);\n\t\t})\n\t\t.exception((ctx, e) -\u003e {  // 通用异常处理\n\t\t\tctx.html(\"mother fucker!\", e.getStatus().code());\n\t\t});\n\n\t\tvar server = new HttpServer(\"localhost\", 8080, 2, 16, rd);\n\t\tserver.start();\n\t\t\n\t\tRuntime.getRuntime().addShutdownHook(new Thread() {\n\n\t\t\tpublic void run() {\n\t\t\t\tserver.stop(); // 优雅停机\n\t\t\t}\n\n\t\t});\t\t\n\t}\n\n}\n\nhttp://localhost:8080/kids\nhttp://localhost:8080/kids/hello\nhttp://localhost:8080/kids/hello.json\nhttp://localhost:8080/kids/world\nhttp://localhost:8080/kids/error\nhttp://localhost:8080/kids/pub/bootstrap.min.css\nhttp://localhost:8080/kids/user\nhttp://localhost:8080/kids/user/hello\n```\n\nDiscussion\n--\n关注公众号「码洞」，我们一起来聊聊这个框架\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyloque%2Fhttpkids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyloque%2Fhttpkids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyloque%2Fhttpkids/lists"}