{"id":16367301,"url":"https://github.com/medz/routingkit","last_synced_at":"2025-03-23T02:32:59.035Z","repository":{"id":212472285,"uuid":"731553490","full_name":"medz/routingkit","owner":"medz","description":"🛸 Routing Kit - Lightweight and fast router for Dart.","archived":false,"fork":false,"pushed_at":"2024-09-30T04:01:46.000Z","size":110,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-12T02:49:28.656Z","etag":null,"topics":["dart","flutter","router","routing","routing-kit"],"latest_commit_sha":null,"homepage":"","language":"Dart","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/medz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"medz"}},"created_at":"2023-12-14T10:39:15.000Z","updated_at":"2024-09-27T14:36:05.000Z","dependencies_parsed_at":"2024-05-10T05:27:08.648Z","dependency_job_id":"7c15725c-0c3c-48d5-9f42-1c53d488fec4","html_url":"https://github.com/medz/routingkit","commit_stats":{"total_commits":60,"total_committers":4,"mean_commits":15.0,"dds":0.08333333333333337,"last_synced_commit":"7d1e06bf0c97c6c5536353ddfeefcc97563cebe9"},"previous_names":["medz/routingkit"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Froutingkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Froutingkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Froutingkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medz%2Froutingkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/medz","download_url":"https://codeload.github.com/medz/routingkit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221842751,"owners_count":16890197,"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":["dart","flutter","router","routing","routing-kit"],"created_at":"2024-10-11T02:49:33.556Z","updated_at":"2025-03-23T02:32:59.016Z","avatar_url":"https://github.com/medz.png","language":"Dart","readme":"\u003ch1 align=\"center\" style=\"font-size: 36px\"\u003eRoutingKit\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pub.dev/packages/routingkit\"\u003e\u003cimg alt=\"Pub Version\" src=\"https://img.shields.io/pub/v/routingkit?logo=dart\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/medz/routingkit/actions/workflows/test.yml\"\u003e\u003cimg alt=\"Test\" src=\"https://github.com/medz/routingkit/actions/workflows/test.yml/badge.svg?branch=main\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/medz/routingkit?tab=MIT-1-ov-file\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/medz/routingkit\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/sponsors/medz\"\u003e\u003cimg alt=\"Sponsors\" src=\"https://img.shields.io/github/sponsors/medz?logo=githubsponsors\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/shiweidu\"\u003e\u003cimg alt=\"X (formerly Twitter) Follow\" src=\"https://img.shields.io/twitter/follow/shiweidu\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nRoutingKit - A lightweight, high-performance router for Dart with an elegant object-oriented API.\n\u003c/p\u003e\n\n## Features\n\n- 🚀 **High Performance**: Optimized route matching using a trie-based structure\n- 🧩 **Flexible Routes**: Support for static, parameterized, and wildcard routes\n- 💪 **Type Safety**: Generic typing for your route handlers\n- 🔍 **Comprehensive Matching**: Find single or all matching routes\n- 🧰 **Object-Oriented API**: Clean interface with clear separation of concerns\n- 🔠 **Case Sensitivity Options**: Configure whether path matching is case sensitive or not\n\n## Installation\n\nRun this command:\n\n```bash\ndart pub add routingkit\n```\n\nWith Flutter:\n\n```bash\nflutter pub add routingkit\n```\n\n## Usage\n\n### Creating a Router\n\n```dart\nimport 'package:routingkit/routingkit.dart';\n\n// Create a typed router (recommended)\nfinal router = createRouter\u003cString\u003e();\n\n// For case-insensitive routing\nfinal caseInsensitiveRouter = createRouter\u003cString\u003e(caseSensitive: false);\n\n// With custom 'any' method token (default is 'any')\nfinal customRouter = createRouter\u003cString\u003e(anyMethodToken: '*');\n```\n\n### Adding Routes\n\nRoutingKit supports various route patterns:\n\n```dart\n// Static routes\nrouter.add('GET', '/users', 'Users list handler');\n\n// Parameter routes (with named parameters)\nrouter.add('GET', '/users/:id', 'User details handler');\n\n// Multiple parameters\nrouter.add('GET', '/users/:id/posts/:postId', 'User post handler');\n\n// Optional parameters (using separate routes)\nrouter.add('GET', '/files/:filename/*', 'File with format handler');\nrouter.add('GET', '/files/:filename', 'File without format handler');\n\n// Wildcard routes\nrouter.add('GET', '/assets/**', 'Static assets handler');\n\n// Named wildcard segments\nrouter.add('GET', '/docs/**:path', 'Documentation handler');\n\n// Method-specific routes\nrouter.add('POST', '/users', 'Create user handler');\nrouter.add('PUT', '/users/:id', 'Update user handler');\nrouter.add('DELETE', '/users/:id', 'Delete user handler');\n```\n\n### Matching Routes\n\nFind the first matching route:\n\n```dart\nfinal match = router.find('GET', '/users/123');\n\nif (match != null) {\n  print('Handler: ${match.data}');\n  print('Parameters: ${match.params}'); // {id: 123}\n}\n```\n\nFind all matching routes (useful for middleware):\n\n```dart\nfinal matches = router.findAll('GET', '/users/123/settings');\n\nfor (final match in matches) {\n  print('Handler: ${match.data}');\n  print('Parameters: ${match.params}');\n}\n```\n\n### Removing Routes\n\n```dart\n// Remove a specific route\nrouter.remove('GET', '/users/:id');\n\n// Remove all routes for a specific method\nrouter.remove('POST', null);\n```\n\n### HTTP Method Handling\n\nRoutingKit automatically normalizes HTTP methods to uppercase. This means that methods like 'get', 'GET', or 'Get' are all treated as 'GET'. This follows the HTTP specification and makes the router more robust.\n\n```dart\nrouter.add('get', '/users', 'get-users');  // Will be normalized to 'GET'\nrouter.add('POST', '/users', 'post-users'); // Will be normalized to 'POST'\n\n// All these will match the same route\nrouter.find('get', '/users');   // Matches\nrouter.find('GET', '/users');   // Matches\nrouter.find('Get', '/users');   // Matches\n```\n\n### Advanced Configuration\n\n#### Case Sensitivity\n\nBy default, RoutingKit performs case-sensitive path matching. You can make path matching case-insensitive:\n\n```dart\n// Create a case-insensitive router\nfinal router = createRouter\u003cString\u003e(caseSensitive: false);\n\n// Add a route with mixed case\nrouter.add('GET', '/Users/:ID', 'user handler');\n\n// All these will match the same route\nfinal match1 = router.find('GET', '/users/123');    // Matches\nfinal match2 = router.find('GET', '/Users/456');    // Matches\nfinal match3 = router.find('GET', '/USERS/789');    // Matches\n\n// Parameter names preserve their original case\nprint(match1.params);  // {ID: 123}\n```\n\n#### Custom Method Tokens\n\nYou can customize the token used to represent any HTTP method:\n\n```dart\nfinal router = createRouter\u003cString\u003e(anyMethodToken: 'ANY_METHOD');\n\n// Add routes with different methods\nrouter.add('GET', '/api', 'get handler');\nrouter.add(null, '/api', 'any handler');  // Uses custom token\n\nrouter.find('POST', '/api')?.data;  // Returns 'any handler'\n```\n\n## Example Applications\n\n### HTTP Server Routing\n\n```dart\nimport 'dart:io';\nimport 'package:routingkit/routingkit.dart';\n\nvoid main() async {\n  final router = createRouter\u003cFunction\u003e();\n\n  // Define routes with handler functions\n  router.add('GET', '/', (req, res) =\u003e res.write('Home page'));\n  router.add('GET', '/users', (req, res) =\u003e res.write('Users list'));\n  router.add('GET', '/users/:id', (req, res) =\u003e res.write('User ${req.params['id']}'));\n\n  final server = await HttpServer.bind('localhost', 8080);\n  print('Server running on http://localhost:8080');\n\n  await for (final request in server) {\n    final response = request.response;\n    final path = request.uri.path;\n    final method = request.method;\n\n    final match = router.find(method, path);\n\n    if (match != null) {\n      final handler = match.data;\n      // Add params to request for handler access\n      (request as dynamic).params = match.params;\n      handler(request, response);\n    } else {\n      response.statusCode = HttpStatus.notFound;\n      response.write('404 Not Found');\n    }\n\n    await response.close();\n  }\n}\n```\n\n## For AI Assistance\n\nRoutingKit includes an `llms.txt` file at the root of the repository. This file is specifically designed to help Large Language Models (LLMs) understand the project structure and functionality.\n\nIf you're using AI tools like GitHub Copilot, Claude, or ChatGPT to work with this codebase, you can point them to the `llms.txt` file for better context and more accurate assistance.\n\n```dart\n// Example: Asking an AI about the project\n\"Please read the llms.txt file in this repository to understand the RoutingKit structure\"\n```\n\nThe file provides AI-friendly documentation including:\n- Project overview and core concepts\n- Code structure explanation\n- API reference and examples\n- Links to relevant implementation files\n\n## Migration Guides\n\n### Migration from Format Parameters\n\nIn versions prior to 0.2.0, RoutingKit supported format parameters using the syntax `:filename.:format?`. This feature has been removed due to implementation complexity and inconsistent behavior.\n\n#### How to Migrate\n\n1. **Replace format parameters with standard path parameters**:\n\n   Before:\n   ```dart\n   router.add('GET', '/files/:filename.:format?', 'File handler');\n   ```\n\n   After:\n   ```dart\n   // For required format\n   router.add('GET', '/files/:filename/:format', 'File handler');\n\n   // For optional format (using two routes)\n   router.add('GET', '/files/:filename/*', 'File with format handler');\n   router.add('GET', '/files/:filename', 'File without format handler');\n   ```\n\n2. **Update parameter access**:\n\n   Before:\n   ```dart\n   final match = router.find('GET', '/files/document.pdf');\n   final filename = match?.params['filename']; // 'document'\n   final format = match?.params['format'];     // 'pdf'\n   ```\n\n   After:\n   ```dart\n   // For standard path parameters\n   final match = router.find('GET', '/files/document/pdf');\n   final filename = match?.params['filename']; // 'document'\n   final format = match?.params['format'];     // 'pdf'\n\n   // For wildcard approach\n   final match = router.find('GET', '/files/document/pdf');\n   final filename = match?.params['filename']; // 'document'\n   final format = match?.params['_0'];         // 'pdf'\n   ```\n\n### Migration from v4.x\n\nSee the [Migration Guide](https://github.com/medz/routingkit/blob/main/CHANGELOG.md#migration-guide) in the changelog.\n\n## License\n\nRoutingKit is open-sourced software licensed under the [MIT license](https://github.com/medz/routingkit?tab=MIT-1-ov-file).\n","funding_links":["https://github.com/sponsors/medz"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedz%2Froutingkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmedz%2Froutingkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedz%2Froutingkit/lists"}