{"id":17077758,"url":"https://github.com/torokmark/routing_python","last_synced_at":"2025-09-17T15:55:06.131Z","repository":{"id":148678957,"uuid":"175883837","full_name":"torokmark/routing_python","owner":"torokmark","description":"Routing mechanism implemented in python.","archived":false,"fork":false,"pushed_at":"2019-03-20T20:56:20.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T12:17:49.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://torokmark.github.io/post/n-ary-routing/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/torokmark.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}},"created_at":"2019-03-15T20:03:56.000Z","updated_at":"2019-03-21T10:17:11.000Z","dependencies_parsed_at":"2023-05-28T15:45:09.147Z","dependency_job_id":null,"html_url":"https://github.com/torokmark/routing_python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/torokmark/routing_python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Frouting_python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Frouting_python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Frouting_python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Frouting_python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/torokmark","download_url":"https://codeload.github.com/torokmark/routing_python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/torokmark%2Frouting_python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275622294,"owners_count":25498325,"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","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-14T12:16:38.526Z","updated_at":"2025-09-17T15:55:06.099Z","avatar_url":"https://github.com/torokmark.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Routing mechanism implemented in python\n\nThis is an experimental project about how to approach routing implementation.\n\nRouting consists of two parts, one is the *route register* which used to declare\npaths with lambdas and methods and, optionally, query params. The other one is the\n*processor* which parse the url, takes the params out of it and returns the\nresult.\n\n## Define a route\n\n`register` function is available for registering routes. It has four params, which are the followings:\n* **route**: define route that can be seen like: `/`, `/users`, `/users/`, \n    `/users/{id}/details/{address_id}/`\n* **callback**: lambda function which is executed if request falls on the route\n* **method**: can be one of the well-known methods. Default to `GET`\n* **params**: list of *queryparams* as a whitelist. Other queryparams wont be processed. \n    Pathparams are optional here.\n\n```python\nrouting.register(route='/users', \n                 callback=(lambda name, email: users.create_user(name, email)),\n                 method=routing.Methods.POST,\n                 params={'name', 'email'})\n\nrouting.register(route='/users/{id}', \n                 callback=(lambda id: users.get_user(id)), \n                 method=routing.Methods.GET)\n```\n\n## Process a call\n\n`process` function takes the following three params and process it. \nThe return value is the result of the executed lambda belongs to the route.\n* **path**: the route\n* **query string params**: dict of query params with their values\n* **method**: the method of the call\n\n```python\nresp_body = routing.process(event.get('path'), \n                            event.get('queryStringParameters'), \n                            event.get('httpMethod'))\n```\n\n`process` raises different kind of errors depending on the error in the path,\nquery or method.\n\nThe following errors can be raised in case of failures.\n\n* **NoRouteFoundError**: raised in case of no registered route found\n* **NoMethodFoundError**: raised in case of no registered route found with the\n    method\n* **RouteNotValidError**: raised when route contains invalid chars\n* **QueryNotValidError**: raised when query contains invalid chars\n\n## Response\n\nThe response body is the return value of the process function which can be an\nobject or `None` in case of void return.\n\n## Entrypoint of a call\n\nConsidered as one entrypoint given, called `handler`, which requires two\nparams, an `event` object which contains the abovementioned key-value pairs and\na `context`.\n\nIt returns a response object which body is serialized by `json.dump`. Also\ncontains status code and encoding.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorokmark%2Frouting_python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorokmark%2Frouting_python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorokmark%2Frouting_python/lists"}