{"id":27259541,"url":"https://github.com/pnxtech/hydradart","last_synced_at":"2025-04-11T04:06:08.508Z","repository":{"id":61975172,"uuid":"489165451","full_name":"pnxtech/HydraDart","owner":"pnxtech","description":"Hydra for Dartlang - A light-weight library for building distributed applications such as microservices.","archived":false,"fork":false,"pushed_at":"2022-05-24T17:13:40.000Z","size":266,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T04:06:05.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pnxtech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-06T00:26:40.000Z","updated_at":"2022-05-06T01:10:37.000Z","dependencies_parsed_at":"2022-10-24T13:45:47.817Z","dependency_job_id":null,"html_url":"https://github.com/pnxtech/HydraDart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2FHydraDart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2FHydraDart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2FHydraDart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2FHydraDart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pnxtech","download_url":"https://codeload.github.com/pnxtech/HydraDart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339281,"owners_count":21087215,"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":"2025-04-11T04:06:07.753Z","updated_at":"2025-04-11T04:06:08.498Z","avatar_url":"https://github.com/pnxtech.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HydraDart\nHydra for [Dartlang](https://dart.dev) - A light-weight library for building distributed applications such as microservices.\n\n![](HydraDart.png)\n\n## Prior work\nHydra for Dart is based on the Hydra approach to building microservices.\n\nSee related repos at: https://github.com/pnxtech\n\nThis implementation for Dart is especially based on HydraPy for Python.\n\n## Example\n\nIn this example HydraDart uses [Dart Shelf](https://pub.dev/packages/shelf) and [Dart Self Router](https://pub.dev/packages/shelf_router) to allow a Dart service to be discoverable within a Docker Swarm or Kubernetes cluster.\n\n```dart\nimport 'dart:io';\nimport 'dart:convert';\nimport 'package:shelf_router/shelf_router.dart';\nimport 'package:shelf/shelf.dart';\nimport 'package:shelf/shelf_io.dart' as io;\nimport './hydra.dart';\n\nclass API {\n  helloHandler(Request request) {\n    return Response.ok('hello-world');\n  }\n\n  userHandler(Request request, String user) {\n    return Response.ok('hello $user');\n  }\n}\n\nvoid main(List\u003cString\u003e args) async {\n  var hydra = Hydra();\n  var router = Router();\n  var api = API();\n\n  hydra.bindRouter(router);\n  hydra.addRoute('/v1/dart', 'get', api.helloHandler);\n  hydra.addRoute('/v1/dart/user/\u003cuser\u003e', 'get', api.userHandler);\n\n  // Load configuration file\n  File configFile = File('./configs/dart-svcs-config.json');\n  Future\u003cString\u003e futureContent = configFile.readAsString();\n  futureContent.then((config) async {\n    Map\u003cString, dynamic\u003e configMap = jsonDecode(config);\n\n    // Use any available host or container IP (usually `0.0.0.0`).\n    final ip = InternetAddress.anyIPv4;\n\n    // Configure a pipeline that logs requests.\n    final routerHandler =\n        Pipeline().addMiddleware(logRequests()).addHandler(router);\n\n    // For running in containers, we respect the PORT environment variable.\n    final port = configMap['hydra']['servicePort'];\n\n    final server = await io.serve(routerHandler, ip, port);\n    print('Server listening on port ${server.port}');\n\n    hydra.init(configMap);\n  });\n}\n```\n\nIn the example above our server application loads a `dart-svcs-config.json` file and passes it along to the `hydra.init()` member function.\n\n```json\n{\n  \"hydra\": {\n    \"serviceName\": \"dart-svcs\",\n    \"serviceIP\": \"\",\n    \"servicePort\": 7134,\n    \"serviceType\": \"test\",\n    \"serviceDescription\": \"Dart experimental service\",\n    \"plugins\": {\n      \"hydraLogger\": {\n        \"logToConsole\": true,\n        \"onlyLogLocally\": false\n      }\n    },\n    \"redis\": {\n      \"urlxxx\": \"redis://redis:6379/15\",\n      \"host\": \"redis\",\n      \"port\": 6379,\n      \"db\": 15\n    }\n  }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnxtech%2Fhydradart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpnxtech%2Fhydradart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnxtech%2Fhydradart/lists"}