{"id":23507692,"url":"https://github.com/timesplinter/lime","last_synced_at":"2025-05-13T00:40:56.582Z","repository":{"id":48849303,"uuid":"382580450","full_name":"TiMESPLiNTER/lime","owner":"TiMESPLiNTER","description":null,"archived":false,"fork":false,"pushed_at":"2021-07-15T12:35:37.000Z","size":150,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T19:22:50.328Z","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/TiMESPLiNTER.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}},"created_at":"2021-07-03T09:52:10.000Z","updated_at":"2021-07-10T13:33:12.000Z","dependencies_parsed_at":"2022-08-31T13:20:20.461Z","dependency_job_id":null,"html_url":"https://github.com/TiMESPLiNTER/lime","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiMESPLiNTER%2Flime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiMESPLiNTER%2Flime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiMESPLiNTER%2Flime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TiMESPLiNTER%2Flime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TiMESPLiNTER","download_url":"https://codeload.github.com/TiMESPLiNTER/lime/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850841,"owners_count":21973667,"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-12-25T10:34:09.877Z","updated_at":"2025-05-13T00:40:56.548Z","avatar_url":"https://github.com/TiMESPLiNTER.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lime - An HTTP micro framework for Java\n\n![CI](https://github.com/timesplinter/lime/actions/workflows/ci.yaml/badge.svg) \n[![JitPack](https://jitpack.io/v/timesplinter/lime.svg)](https://jitpack.io/#timesplinter/lime)\n\nLime is heavily inspired by the popular micro framework Slim for PHP.\n\n## Get started\n\nThis example app configuration will create an app instance handling `GET` requests for route `/test/{id}` using Java's \nbuilt-in HTTP server.\n\n```java\npublic class MyApp\n{\n    final private static int APP_PORT = 8989;\n    \n    public static void main(String[] args)\n    {\n        // Create a dependency container instance\n        Container container = new Container();\n\n        // Create a response factory instance\n        ResponseFactoryInterface responseFactory = new ResponseFactory();\n        \n        // Instantiate the app\n        App app = new App(container);\n\n        // Add default routing middleware to route incoming requests\n        app.addDefaultRoutingMiddleware();\n\n        app.get(\"/test/{id}\", request -\u003e {\n            int id = Integer.parseInt((String) request.getAttribute(\"id\"));\n\n            var response = responseFactory.create();\n\n            response.setStatusCode(200).setHeader(\"Content-Type\", \"text/plain\");\n            response.getBody().write(\"This is the response for id: \" + id);\n\n            return response;\n        });\n        \n        try {\n            // Create a Java built-in HTTP server instance,\n            // listen on port 8989 and connect it to the app instance\n            HttpServer httpServer = HttpServer.create(new InetSocketAddress(MyApp.APP_PORT), 0);\n\n            JavaHttpServerBridge.attach(httpServer, app);\n\n            httpServer.setExecutor(null);\n            httpServer.start();\n        } catch (IOException e) {\n            System.err.println(\"Could not create HTTP server: \" + e.getMessage());\n        }\n    }\n}\n```\n\nRequests to `GET http://localhost:8989/test/42` will now be answered with:\n\n```\nHTTP/1.1 200 OK\nDate: Sat, 03 Jul 2021 08:55:24 GMT\nContent-length: 32\nContent-Type: text/plain\n\nThis is the response for id: 42\n```\n\n## Middleware support\n\n## Dependency injection container\n\nThe dependency injection container allows you to define services lazily. This means they're only instantiated if and \nwhen they're used for the first time during runtime.\n\n### Example\n```java\nvar container = new Container();\n\n// Service definition\ncontainer.set(\"myService\", () -\u003e {\n    String pattern = \"yyyy-MM-dd\";\n    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);\n\n    return simpleDateFormat.format(new Date());\n});\n\n// Service retrieval\nvar myService = (String) container.get(\"myService\");\n```\n\n### Pre-compiling\nThere's also the option to precompile the container with the method `Container::precompile` and instantiate all services\nat once instead of on the fly with their first usage. This might be useful if you anyway know that all defined services \nwill be used at some point during a long-running process.\n\n## Routing\n### Placeholders\n```java\n// Match any value (without \"/\")\napp.get(\"/test/{id}\", request -\u003e { /* ... */ });\n\n// Match only numbers\napp.get(\"/test/{id:\\\\d+}\", request -\u003e { /* ... */ });\n\n// Match only something that starts with \"foo\"\napp.get(\"/test/{id: foo.+}\", request -\u003e { /* ... */ })\n```\n\nRoute matching is case-insensitive.\n\n### Groups\n```java\napp.group(\"/user\", routeCollector -\u003e {\n    routeCollector.get(\"\", request -\u003e { /* ... */ });\n    routeCollector.post(\"\", request -\u003e { /* ... */ });\n    routeCollector.get(\"/{id: \\\\d+}\", request -\u003e { /* ... */ });\n}).add(new MyMiddleware());\n```\n\nThis defines three routes:\n\n* `GET /user`\n* `POST /user`\n* `GET /user/42`\n\nand adds `MyMiddleware` to all three of them.\n\nAs you can see, groups can also have middlewares appended which only affect that very group.\n\n## Build\n```bash\n$ gradle build\n```\n\nThis will produce two jars (`lime-x.y.z.jar` and `lime-x.y.z-sources.jar`) in `./build/libs`.\n\n## Test\n```bash\n$ gradle test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimesplinter%2Flime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimesplinter%2Flime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimesplinter%2Flime/lists"}