{"id":42667850,"url":"https://github.com/oboard/mio","last_synced_at":"2026-01-29T10:13:13.257Z","repository":{"id":294863513,"uuid":"988196171","full_name":"oboard/mio","owner":"oboard","description":"A powerful HTTP networking package for MoonBit.","archived":false,"fork":false,"pushed_at":"2025-10-18T12:32:41.000Z","size":114,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T07:44:43.831Z","etag":null,"topics":["mio","moonbit","moonbitlang","network","request"],"latest_commit_sha":null,"homepage":"https://mooncakes.io/docs/oboard/mio","language":"MoonBit","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/oboard.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-22T07:38:54.000Z","updated_at":"2025-10-18T12:32:45.000Z","dependencies_parsed_at":"2025-08-10T10:10:48.797Z","dependency_job_id":"f7e299d9-1b48-4cdd-9f4e-838e0a9062a1","html_url":"https://github.com/oboard/mio","commit_stats":null,"previous_names":["oboard/mio"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oboard/mio","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oboard%2Fmio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oboard%2Fmio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oboard%2Fmio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oboard%2Fmio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oboard","download_url":"https://codeload.github.com/oboard/mio/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oboard%2Fmio/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28875450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T09:47:23.353Z","status":"ssl_error","status_checked_at":"2026-01-29T09:47:19.357Z","response_time":59,"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":["mio","moonbit","moonbitlang","network","request"],"created_at":"2026-01-29T10:13:10.913Z","updated_at":"2026-01-29T10:13:13.241Z","avatar_url":"https://github.com/oboard.png","language":"MoonBit","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oboard/mio\n\nA powerful and modern HTTP networking library for MoonBit with multi-backend support.\n\n[![Version](https://img.shields.io/badge/version-0.3.0-blue.svg)](https://github.com/oboard/mio)\n[![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)\n\n## Features\n\n- 🚀 **Async/Await Support**: Built-in async operations with `@mio.run`\n- 🌐 **Complete HTTP Methods**: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, CONNECT, TRACE\n- 📄 **JSON Handling**: Seamless JSON parsing and response handling\n- 📁 **File Downloads**: Built-in file download capabilities with custom save paths\n- 🌊 **Stream Processing**: Real-time data streaming with callback support\n- 📦 **Binary Data Support**: Native handling of binary data with unified `Bytes` interface across all backends\n- 🎯 **Multi-Backend**: Support for Native (libcurl), JavaScript (Fetch API), and WASM\n- ⚡ **Type Safety**: Full MoonBit type system support with error handling\n- 🔧 **Flexible Options**: Headers, credentials, modes, and request customization\n\n## Backend Support\n\n### Native Backend (`native`, `llvm`)\n- **HTTP Engine**: libcurl for robust HTTP requests\n- **Features**: All HTTP methods, file downloads, full header support\n- **Dependencies**: Requires libcurl system library\n- **Performance**: Optimized for server-side and native applications\n\n### JavaScript Backend (`js`)\n- **HTTP Engine**: Fetch API\n- **Features**: Browser and Node.js compatibility\n- **Dependencies**: No external dependencies\n- **Performance**: Optimized for web applications and frontend development\n\n### WebAssembly Backend (`wasm`, `wasm-gc`)\n- **HTTP Engine**: WASM-compatible implementation\n- **Features**: Cross-platform WebAssembly support\n- **Dependencies**: WASM runtime environment\n- **Performance**: Optimized for WASM applications\n\n## Installation\n\nAdd to your `moon.mod.json`:\n\n```json\n{\n  \"deps\": {\n    \"oboard/mio\": \"0.3.0\"\n  }\n}\n```\n\n## Quick Start\n\n### Basic GET Request\n\n```moonbit\n@mio.run(fn() {\n  match (try? @mio.get(\"https://api.github.com\")) {\n    Ok(response) =\u003e {\n      println(\"Status: \" + response.statusCode.to_string())\n      println(\"Response: \" + response.text())\n    }\n    Err(e) =\u003e println(\"Error: \" + e.to_string())\n  }\n})\n```\n\n### POST Request with JSON Data\n\n```moonbit\n@mio.run(fn() {\n  match (try? @mio.post(\"https://httpbin.org/post\", \n    data={ \n      \"name\": \"MoonBit\", \n      \"version\": \"0.3.0\",\n      \"features\": [\"async\", \"http\", \"json\"]\n    })) {\n    Ok(response) =\u003e {\n      println(\"Posted successfully!\")\n      println(response.unwrap_json())\n    }\n    Err(e) =\u003e println(\"Failed: \" + e.to_string())\n  }\n})\n```\n\n### Custom Headers and Options\n\n```moonbit\n@mio.run(fn() {\n  let headers = {\n    \"Authorization\": \"Bearer your-token\",\n    \"User-Agent\": \"MoonBit-App/1.0\",\n    \"Accept\": \"application/json\"\n  }\n  \n  match (try? @mio.get(\"https://api.example.com/data\", \n    headers=headers,\n    credentials=SameOrigin,\n    mode=CORS)) {\n    Ok(response) =\u003e {\n      if response.statusCode == 200 {\n        let data = response.json()\n        // Process your data\n      }\n    }\n    Err(e) =\u003e println(\"Request failed: \" + e.to_string())\n  }\n})\n```\n\n### File Download\n\n```moonbit\n@mio.run(fn() {\n  // Download with custom filename\n  match (try? @mio.download(\"https://api.github.com/repos/moonbitlang/core\",\n    save_path=\"github_repo.json\")) {\n    Ok(_) =\u003e println(\"File downloaded successfully!\")\n    Err(e) =\u003e println(\"Download failed: \" + e.to_string())\n  }\n  \n  // Download with dynamic filename based on headers\n  match (try? @mio.download(\"https://example.com/file.zip\",\n    save_path_fn=fn(headers) {\n      match headers.get(\"content-disposition\") {\n        Some(disposition) =\u003e extract_filename(disposition)\n        None =\u003e \"downloaded_file.zip\"\n      }\n    })) {\n    Ok(_) =\u003e println(\"File downloaded with dynamic name!\")\n    Err(e) =\u003e println(\"Download failed: \" + e.to_string())\n  }\n})\n```\n\n### Stream Requests\n\n```moonbit\n@mio.run(fn() {\n  // Stream processing with real-time data handling\n  let chunks = []\n  \n  match (try? @mio.get_stream(\"https://api.example.com/stream\",\n    fn(chunk) {\n      println(\"Received chunk: \" + chunk)\n      chunks.push(chunk)\n      // Process each chunk as it arrives\n    })) {\n    Ok(response) =\u003e {\n      println(\"Stream completed with status: \" + response.statusCode.to_string())\n      println(\"Total chunks received: \" + chunks.length().to_string())\n    }\n    Err(e) =\u003e println(\"Stream failed: \" + e.to_string())\n  }\n})\n```\n\n**Note**: Stream functionality is currently under development for native backend due to callback compatibility issues between MoonBit and C function pointers. It works properly on JavaScript and WASM backends.\n\n## API Reference\n\n### HTTP Methods\n\nAll HTTP methods support the same optional parameters:\n\n- `headers?: Map[String, String]` - Custom HTTP headers\n- `credentials?: FetchCredentials` - Request credentials (Omit, SameOrigin, Include)\n- `mode?: FetchMode` - Request mode (CORS, NoCORS, SameOrigin, Navigate)\n\n```moonbit\n// GET request\n(try? @mio.get(url, headers?, credentials?, mode?))\n\n// POST request with body or JSON data\n(try? @mio.post(url, body?, data?, headers?, credentials?, mode?))\n\n// Other HTTP methods\n(try? @mio.put(url, body?, headers?, credentials?, mode?))\n(try? @mio.delete(url, body?, headers?, credentials?, mode?))\n(try? @mio.patch(url, body?, headers?, credentials?, mode?))\n(try? @mio.options(url, body?, headers?, credentials?, mode?))\n(try? @mio.head(url, body?, headers?, credentials?, mode?))\n(try? @mio.connect(url, body?, headers?, credentials?, mode?))\n(try? @mio.trace(url, body?, headers?, credentials?, mode?))\n\n// Stream request with callback for real-time data processing\n(try? @mio.get_stream(url, callback, headers?, credentials?, mode?))\n```\n\n### Response Handling\n\n```moonbit\n// HttpResponse methods\nresponse.text()          // Get response as string\nresponse.json()          // Parse JSON (may raise ParseError)\nresponse.unwrap_json()   // Safe JSON parsing (returns Json::null() on error)\nresponse.statusCode      // HTTP status code\nresponse.headers         // Response headers as Map[String, String]\nresponse.data           // Raw response data as Bytes\n```\n\n### Error Handling\n\nThe library defines three main error types:\n\n- `IOError` - File system and I/O related errors\n- `NetworkError` - Network and HTTP request errors  \n- `ExecError` - Execution and runtime errors\n\n## Advanced Usage\n\n### Custom Request with Full Control\n\n```moonbit\n@mio.run(fn() {\n  match (try? @mio.request(\"https://api.example.com/upload\",\n    http_method=POST,\n    body=\"custom request body\",\n    headers={\n      \"Content-Type\": \"text/plain\",\n      \"X-Custom-Header\": \"value\"\n    },\n    credentials=Include,\n    mode=CORS)) {\n    Ok(response) =\u003e {\n      // Handle response\n    }\n    Err(NetworkError) =\u003e {\n      // Handle network errors\n    }\n  }\n})\n```\n\n### Binary Data Handling\n\nMio provides unified binary data support across all backends through the `Bytes` interface. All HTTP responses contain raw binary data in `response.data`, which can be processed as text or kept as binary.\n\n```moonbit\n@mio.run(fn() {\n  // All requests return binary data in response.data\n  match (try? @mio.get(\"https://example.com/image.png\")) {\n    Ok(response) =\u003e {\n      // response.data contains raw bytes (unified across all backends)\n      @fs.write_bytes_to_file(\"image.png\", response.data)\n      \n      // For text content, use response.text()\n      let text_content = response.text()\n      println(\"Content: \" + text_content)\n    }\n    Err(e) =\u003e println(\"Failed to download: \" + e.to_string())\n  }\n})\n\n```\n\n## Examples\n\nCheck out these real-world projects using mio:\n\n- **[weatherquery](https://github.com/oboard/weatherquery)** - Weather query tool for Chinese locations\n  - Fetches real-time weather data from APIs\n  - Supports provinces, cities, and districts\n  - Cross-platform (native and web)\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foboard%2Fmio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foboard%2Fmio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foboard%2Fmio/lists"}