{"id":22767982,"url":"https://github.com/hayasshi/akka-http-router","last_synced_at":"2025-06-11T22:09:23.873Z","repository":{"id":23513503,"uuid":"82457499","full_name":"hayasshi/akka-http-router","owner":"hayasshi","description":"A simple library for route definition of akka-http.","archived":false,"fork":false,"pushed_at":"2024-08-12T21:18:01.000Z","size":66,"stargazers_count":19,"open_issues_count":42,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T01:41:08.764Z","etag":null,"topics":["akka-http","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/hayasshi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-02-19T12:32:40.000Z","updated_at":"2023-11-10T07:11:31.000Z","dependencies_parsed_at":"2025-04-15T01:37:56.672Z","dependency_job_id":"79537d3d-609f-4506-a41b-d5f3ccd79f0d","html_url":"https://github.com/hayasshi/akka-http-router","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/hayasshi/akka-http-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayasshi%2Fakka-http-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayasshi%2Fakka-http-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayasshi%2Fakka-http-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayasshi%2Fakka-http-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hayasshi","download_url":"https://codeload.github.com/hayasshi/akka-http-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayasshi%2Fakka-http-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259353328,"owners_count":22844750,"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":["akka-http","scala"],"created_at":"2024-12-11T14:09:19.040Z","updated_at":"2025-06-11T22:09:23.855Z","avatar_url":"https://github.com/hayasshi.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# akka-http-router\n\n```scala\nimport akkahttp_router._\n\nimport akka.http.scaladsl.model.HttpMethods._\nimport akka.http.scaladsl.server.Directives._\n\nval controller = new ControllerYouDefined(???)\n\nval categoryId = LongNumber\nval productId = LongNumber\n\nval router = Router(\n  route(GET,  \"category\", controller.getCategories),\n  route(POST, \"category\", controller.postCategory),\n\n  route(GET,  \"category\" / categoryId, controller.getCategory),\n\n  route(GET,  \"category\" / categoryId / \"products\", controller.getProducts),\n  route(POST, \"category\" / categoryId / \"products\", controller.postProduct),\n\n  route(GET,  \"category\" / categoryId / \"products\" / productId, controller.getProduct)\n)\nval v1api = pathPrefix(\"v1\")(router.route)\n\nHttp().bindAndHandle(v1api, \"localhost\", 8080)\n```\n\n## Motivation\n\nThe [akka-http](http://doc.akka.io/docs/akka-http/current/index.html) is a great tool kit for building to web service interface!\n\nHowever, I do not want to deeply nest route definitions, like this:\n\n```scala\nval route = pathPrefix(\"v1\") {\n  path(\"category\") {\n    get {\n      ???\n    } ~\n    post {\n      ???\n    }\n  } ~\n  path(\"category\" / LongNumber) { cid =\u003e\n    get {\n      ???\n    } ~\n    path(\"products\") {\n      get {\n        ???\n      } ~\n      post {\n        ???\n      } ~\n    } ~\n    path(\"products\" / LongNumber) { pid =\u003e\n      ???\n    }\n  }\n}\n```\n\nAnd, `Directives` create more nested. :-(\n\nI think this route definition is contained two problems.\n\n- Bad visibility.\n- To become fat `Route`.\n\nThis tool separates route definition and application logic like the [PlayFramework's router](https://www.playframework.com/documentation/2.5.x/ScalaRouting).\n\n## Installation\n\n```scala\nresolvers += Resolver.sonatypeRepo(\"releases\")\n\nlibraryDependencies += \"com.github.hayasshi\" %% \"akka-http-router\" % \"0.5.1\"\n```\n\n## Usage\n\nDefine a function matching the number of URL path parameters.\n\n```scala\nval getCategories: Route = ???\nval getProducts: Long =\u003e Route = ???\nval getProduct: ((Long, Long)) =\u003e Route = ???\n```\n\nAnd defined.\n\n```scala\nimport akkahttp_router._\n\nimport akka.http.scaladsl.model.HttpMethods._\nimport akka.http.scaladsl.server.Directives._\n\nval router = Router(\n  route(GET, \"category\", getCategories),\n\n  route(GET, \"category\" / LongNumber / \"products\", getProducts),\n\n  route(GET, \"category\" / LongNumber / \"products\" / LongNumber, getProduct)\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayasshi%2Fakka-http-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhayasshi%2Fakka-http-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayasshi%2Fakka-http-router/lists"}