{"id":13552179,"url":"https://github.com/dint-dev/universal_io","last_synced_at":"2026-01-11T13:31:43.874Z","repository":{"id":56826998,"uuid":"146784535","full_name":"dint-dev/universal_io","owner":"dint-dev","description":"Cross-platform 'dart:io', including browser-compatible HttpClient.","archived":false,"fork":false,"pushed_at":"2025-11-16T22:26:30.000Z","size":683,"stargazers_count":101,"open_issues_count":9,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-04T06:19:30.552Z","etag":null,"topics":["dart","flutter"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/universal_io","language":"Dart","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/dint-dev.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-08-30T17:38:31.000Z","updated_at":"2025-12-12T20:30:08.000Z","dependencies_parsed_at":"2024-04-17T21:02:06.640Z","dependency_job_id":null,"html_url":"https://github.com/dint-dev/universal_io","commit_stats":{"total_commits":70,"total_committers":4,"mean_commits":17.5,"dds":0.2142857142857143,"last_synced_commit":"3f23477b0976754a7c4e4976401316ae4055c585"},"previous_names":["dart-io-packages/universal_io","terrier989/universal_io"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/dint-dev/universal_io","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dint-dev%2Funiversal_io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dint-dev%2Funiversal_io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dint-dev%2Funiversal_io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dint-dev%2Funiversal_io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dint-dev","download_url":"https://codeload.github.com/dint-dev/universal_io/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dint-dev%2Funiversal_io/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28304263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["dart","flutter"],"created_at":"2024-08-01T12:02:00.194Z","updated_at":"2026-01-11T13:31:43.852Z","avatar_url":"https://github.com/dint-dev.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"[![Pub Package](https://img.shields.io/pub/v/universal_io.svg)](https://pub.dartlang.org/packages/universal_io)\n[![package publisher](https://img.shields.io/pub/publisher/universal_io.svg)](https://pub.dev/packages/universal_io/publisher)\n[![Github Actions CI](https://github.com/dint-dev/universal_io/workflows/Dart%20CI/badge.svg)](https://github.com/dint-dev/universal_io/actions)\n\n# Overview\nA cross-platform [dart:io](https://api.dart.dev/dart-io/) that works on all platforms, including browsers.\n\nYou can simply replace _dart:io_ imports with _package:universal_io/universal_io.dart_.\n\nLicensed under the [Apache License 2.0](LICENSE).\nSome of the source code was derived [from Dart SDK](https://github.com/dart-lang/sdk/tree/master/sdk/lib/io),\nwhich was obtained under the BSD-style license of Dart SDK. See LICENSE file for details.\n\n## APIs added on top of \"dart:io\"\n* [BrowserHttpClient](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClient-class.html)\n  * A subclass of \"dart:io\" [HttpClient](https://api.dart.dev/dart-io/HttpClient-class.html)\n    that works in browsers.\n  * See also\n    [BrowserHttpClientRequest](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientRequest-class.html),\n    [BrowserHttpClientResponse](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientResponse-class.html),\n    and [BrowserHttpClientException](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClientException-class.html).\n  * Uses XMLHttpRequest in browsers. WASM-compatible.\n* [HttpClient](https://pub.dev/documentation/universal_io/latest/universal_io/HttpClient-class.html)\n    * `HttpClient()` factory is changed so that it returns BrowserHttpClient on browsers.\n* [Platform](https://pub.dev/documentation/universal_io/latest/universal_io/Platform-class.html)\n    * The package makes methods like `Platform.isAndroid` and `Platform.isMacOS` work in the\n      browsers too.\n* [InternetAddress](https://pub.dev/documentation/universal_io/latest/universal_io/InternetAddress-class.html)\n    * The package makes it works in the browsers too.\n* [BytesBuilder](https://pub.dev/documentation/universal_io/latest/universal_io/BytesBuilder-class.html)\n    * The package makes it works in the browsers too.\n\n## Links\n  * [API reference](https://pub.dev/documentation/universal_io/latest/)\n  * [Github project](https://github.com/dint-dev/universal_io)\n    * We appreciate feedback, issue reports, and pull requests.\n\n## Similar packages\n  * [universal_html](https://pub.dev/packages/universal_html) (cross-platform DOM, CSS, etc.)\n\n\n# Getting started\n## 1.Add dependency\nIn pubspec.yaml:\n```yaml\ndependencies:\n  universal_io: ^2.3.0\n```\n\n## 2.Use HTTP client\n```dart\n// Replace 'dart:io' imports with the following:\nimport 'package:universal_io/universal_io.dart';\n\nFuture\u003cvoid\u003e main() async {\n  // HttpClient can now be used in browser too!\n  final httpClient = newUniversalHttpClient();\n  final request = await httpClient.getUrl(Uri.parse(\"https://dart.dev/\"));\n  final response = await request.close();\n}\n```\n\n# HTTP client behavior\nHTTP client is implemented with [XMLHttpRequest (XHR)](https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest)\nAPI on browsers.\n\nXHR causes the following differences with _dart:io_:\n  * HTTP connection is created only after `request.close()` has been called.\n  * Same-origin policy limitations. For making cross-origin requests, see documentation below.\n\n## Helpful error messages\nWhen requests fail and assertions are enabled, error messages contains descriptions how to fix\npossible issues such as missing cross-origin headers.\n\nThe error messages look like the following:\n```text\nXMLHttpRequest error.\n-------------------------------------------------------------------------------\nHTTP method:             PUT\nHTTP URL:                http://destination.com/example\nOrigin:                  http://source.com\nCross-origin:            true\nbrowserCredentialsMode:  false\nbrowserResponseType:     arraybuffer\n\nTHE REASON FOR THE XHR ERROR IS UNKNOWN.\n(For security reasons, browsers do not explain XHR errors.)\n\nIs the server down? Did the server have an internal error?\n\nEnabling credentials mode would enable use of some HTTP headers in both the\nrequest and the response. For example, credentials mode is required for\nsending/receiving cookies. If you think you need to enable 'credentials mode',\ndo the following:\n\n    final httpClientRequest = ...;\n    if (httpClientRequest is BrowserHttpClientRequest) {\n      httpClientRequest.browserCredentialsMode = true;\n    }\n\nDid the server respond to a cross-origin \"preflight\" (OPTIONS) request?\n\nDid the server send the following headers?\n  * Access-Control-Allow-Origin: http://source.com\n    * You can also use wildcard (\"*\").\n    * Always required for cross-origin requests!\n  * Access-Control-Allow-Methods: PUT\n    * You can also use wildcard (\"*\").\n```\n\nSometimes when you do cross-origin requests in browsers, you want to use\n[CORS \"credentials mode\"](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). This can be\nachieved with the following pattern:\n```dart\nimport 'package:universal_io/universal_io.dart';\n\nFuture\u003cvoid\u003e main() async {\n    final client = newUniversalHttpClient();\n    final request = client.getUrl(Url.parse('http://example/url'));\n\n    // Enable credentials mode\n    if (request is BrowserHttpClientRequest) {\n      request.browserCredentialsMode = true;\n    }\n\n    // Close request\n    final response = await request.close();\n    // ...\n}\n```\n\n## Streaming text responses\nThe underlying XMLHttpRequest (XHR) API supports response streaming only when _responseType_ is\n\"text\". This works for responses that are UTF-8 text.\n\nThis package automatically uses _responseType_ \"text\" based on value of the\nHTTP request header \"Accept\". These media types are defined\n[BrowserHttpClient.defaultTextMimes](https://pub.dev/documentation/universal_io/latest/universal_io/BrowserHttpClient/defaultTextMimes.html).\n\nIf you want to disable streaming, use the following pattern:\n```dart\nimport 'package:universal_io/universal_io.dart';\n\nFuture\u003cvoid\u003e main() async {\n    final client = newUniversalHttpClient();\n    if (client is BrowserHttpClient) {\n      client.onBrowserHttpClientRequestClose = (request) {\n        if (someCondition) {\n          request.browserResponseType = 'text';\n        }\n      };\n    }\n    // ...\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdint-dev%2Funiversal_io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdint-dev%2Funiversal_io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdint-dev%2Funiversal_io/lists"}