{"id":28591249,"url":"https://github.com/muntasirszn/fetchttp","last_synced_at":"2026-03-11T17:02:48.136Z","repository":{"id":297396413,"uuid":"996601345","full_name":"MuntasirSZN/fetchttp","owner":"MuntasirSZN","description":"`fetch` Web API Implementation In Rust!","archived":false,"fork":false,"pushed_at":"2025-09-16T01:01:56.000Z","size":279,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-16T03:12:14.694Z","etag":null,"topics":["client","fetch","http","hyper","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/fetchttp","language":"Rust","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/MuntasirSZN.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","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-06-05T07:23:35.000Z","updated_at":"2025-09-16T01:01:52.000Z","dependencies_parsed_at":"2025-06-05T10:24:06.341Z","dependency_job_id":"e7673df6-01a9-4741-be52-b32e05a6cd8c","html_url":"https://github.com/MuntasirSZN/fetchttp","commit_stats":null,"previous_names":["muntasirszn/fetchttp","muntasirszn/fetch-rs"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MuntasirSZN/fetchttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuntasirSZN%2Ffetchttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuntasirSZN%2Ffetchttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuntasirSZN%2Ffetchttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuntasirSZN%2Ffetchttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MuntasirSZN","download_url":"https://codeload.github.com/MuntasirSZN/fetchttp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuntasirSZN%2Ffetchttp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276312967,"owners_count":25620626,"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-21T02:00:07.055Z","response_time":72,"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":["client","fetch","http","hyper","rust"],"created_at":"2025-06-11T09:14:09.546Z","updated_at":"2025-09-21T21:49:52.287Z","avatar_url":"https://github.com/MuntasirSZN.png","language":"Rust","readme":"# fetchttp\n\n[![Crates.io](https://img.shields.io/crates/v/fetchttp)](https://crates.io/crates/fetchttp)\n[![Documentation](https://docs.rs/fetchttp/badge.svg)](https://docs.rs/fetchttp)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![CI](https://github.com/MuntasirSZN/fetchttp/actions/workflows/test.yml/badge.svg)](https://github.com/MuntasirSZN/fetchttp/actions/workflows/test.yml)\n\nA **WHATWG Fetch API** compliant HTTP client library for Rust that provides the familiar `fetch()` interface you know and love from web development.\n\n## ✨ Features\n\n- 🌐 **WHATWG Fetch API Compliant** - Follows the official specification\n- 🚀 **Async/Await Support** - Built on Tokio for modern async Rust  \n- 🔒 **Type Safety** - Leverages Rust's type system for safe HTTP operations\n- 📦 **JSON Support** - Built-in JSON serialization/deserialization with serde\n- 🔧 **Flexible Bodies** - Support for text, bytes, and JSON request/response bodies\n- 📋 **Header Management** - Complete header manipulation API\n- 🔄 **Request/Response Cloning** - Efficient cloning following the specification\n- ⏹️ **Abort Signals** - Request cancellation support\n- 🔗 **Connection Pooling** - Automatic connection reuse for better performance\n\n## 🚀 Quick Start\n\nAdd `fetchttp` to your `Cargo.toml`:\n\n```toml\n[dependencies]\nfetchttp = \"1.0.0\"\ntokio = { version = \"1.0\", features = [\"full\"] }\nserde_json = \"1.0\"  # For JSON support\n```\n\n### Simple GET Request\n\n```rust\nuse fetchttp::*;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let response = fetch(\"https://api.github.com/users/octocat\", None).await?;\n    \n    if response.ok() {\n        let user: serde_json::Value = response.json().await?;\n        println!(\"User: {}\", user[\"name\"]);\n    }\n    \n    Ok(())\n}\n```\n\n### POST Request with JSON\n\n```rust\nuse fetchttp::*;\nuse serde_json::json;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let data = json!({\n        \"name\": \"John Doe\",\n        \"email\": \"john@example.com\"\n    });\n    \n    let mut init = RequestInit::new();\n    init.method = Some(\"POST\".to_string());\n    init.body = Some(ReadableStream::from_json(\u0026data));\n    \n    let response = fetch(\"https://api.example.com/users\", Some(init)).await?;\n    \n    if response.ok() {\n        println!(\"User created successfully!\");\n    }\n    \n    Ok(())\n}\n```\n\n### Custom Headers\n\n```rust\nuse fetchttp::*;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let mut headers = Headers::new();\n    headers.set(\"Authorization\", \"Bearer your-token\")?;\n    headers.set(\"User-Agent\", \"MyApp/1.0\")?;\n    \n    let mut init = RequestInit::new();\n    init.headers = Some(headers);\n    \n    let response = fetch(\"https://api.example.com/protected\", Some(init)).await?;\n    let text = response.text().await?;\n    \n    println!(\"Response: {}\", text);\n    Ok(())\n}\n```\n\n### Request Cancellation\n\n```rust\nuse fetchttp::*;\nuse std::time::Duration;\nuse tokio::time::sleep;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let controller = AbortController::new();\n    let signal = controller.signal().clone();\n    \n    let mut init = RequestInit::new();\n    init.signal = Some(signal);\n    \n    // Cancel the request after 1 second\n    tokio::spawn(async move {\n        sleep(Duration::from_secs(1)).await;\n        controller.abort();\n    });\n    \n    match fetch(\"https://httpbin.org/delay/5\", Some(init)).await {\n        Ok(response) =\u003e println!(\"Request completed: {}\", response.status()),\n        Err(FetchError::Abort(_)) =\u003e println!(\"Request was cancelled\"),\n        Err(e) =\u003e println!(\"Request failed: {}\", e),\n    }\n    \n    Ok(())\n}\n```\n\n## 📚 API Reference\n\n### Core Functions\n\n- **`fetch(url, init)`** - Perform an HTTP request\n  \n### Request Types\n\n- **`Request`** - Represents an HTTP request\n- **`RequestInit`** - Configuration for requests\n- **`RequestMode`** - CORS mode settings\n- **`RequestCredentials`** - Credential handling\n- **`RequestCache`** - Cache control\n- **`RequestRedirect`** - Redirect handling\n\n### Response Types\n\n- **`Response`** - Represents an HTTP response\n- **`ResponseInit`** - Configuration for responses  \n- **`ResponseType`** - Response type information\n\n### Body and Streams\n\n- **`ReadableStream`** - Request/response body handling\n- **`Headers`** - HTTP header management\n\n### Error Handling\n\n- **`FetchError`** - Main error type\n- **`TypeError`** - Type validation errors\n- **`NetworkError`** - Network-related errors\n- **`AbortError`** - Request cancellation errors\n\n### Abort Support\n\n- **`AbortController`** - Controls request cancellation\n- **`AbortSignal`** - Signals request cancellation\n\n## 🔄 Body Consumption\n\nResponse and request bodies can be consumed in multiple ways:\n\n```rust\n// Text\nlet text = response.text().await?;\n\n// JSON  \nlet data: MyStruct = response.json().await?;\n\n// Bytes\nlet bytes = response.array_buffer().await?;\n\n// Blob (alias for array_buffer)\nlet blob = response.blob().await?;\n```\n\n## 🛡️ Error Handling\n\nThe library provides comprehensive error handling:\n\n```rust\nmatch fetch(\"https://example.com\", None).await {\n    Ok(response) =\u003e {\n        if response.ok() {\n            println!(\"Success: {}\", response.status());\n        } else {\n            println!(\"HTTP Error: {}\", response.status());\n        }\n    }\n    Err(FetchError::Type(e)) =\u003e {\n        eprintln!(\"Type error: {}\", e);\n    }\n    Err(FetchError::Network(e)) =\u003e {\n        eprintln!(\"Network error: {}\", e);\n    }\n    Err(FetchError::Abort(e)) =\u003e {\n        eprintln!(\"Request aborted: {}\", e);\n    }\n}\n```\n\n## 🔧 Advanced Usage\n\n### Custom HTTP Methods\n\n```rust\nlet mut init = RequestInit::new();\ninit.method = Some(\"PATCH\".to_string());\ninit.body = Some(ReadableStream::from_json(\u0026data));\n\nlet response = fetch(\"https://api.example.com/resource/1\", Some(init)).await?;\n```\n\n### File Upload\n\n```rust\nuse std::fs;\n\nlet file_content = fs::read(\"document.pdf\")?;\n\nlet mut init = RequestInit::new();\ninit.method = Some(\"POST\".to_string());\ninit.body = Some(ReadableStream::from_bytes(file_content.into()));\n\nlet response = fetch(\"https://api.example.com/upload\", Some(init)).await?;\n```\n\n### Response Headers\n\n```rust\nlet response = fetch(\"https://httpbin.org/response-headers\", None).await?;\n\nfor (name, value) in response.headers().entries() {\n    println!(\"{}: {}\", name, value);\n}\n\n// Check specific header\nif let Some(content_type) = response.headers().get(\"content-type\")? {\n    println!(\"Content-Type: {}\", content_type);\n}\n```\n\n## 🏗️ Building and Testing\n\n```bash\n# Build the library\ncargo build\n\n# Run tests\ncargo test\n\n# Run benchmarks\ncargo bench\n\n# Generate documentation\ncargo doc --open\n```\n\n## 📊 Performance\n\nThe library is designed for performance with:\n\n- Connection pooling via hyper\n- Efficient body streaming\n- Zero-copy operations where possible\n- Minimal allocations\n\nSee `benches/` for detailed performance benchmarks.\n\n## 🤝 Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🌟 Comparison with Other Libraries\n\n| Feature | fetchttp | reqwest | hyper | ureq |\n|---------|----------|---------|-------|------|\n| WHATWG Fetch API | ✅ | ❌ | ❌ | ❌ |\n| Async/Await | ✅ | ✅ | ✅ | ❌ |\n| JSON Support | ✅ | ✅ | ❌ | ✅ |\n| Connection Pooling | ✅ | ✅ | ✅ | ❌ |\n| Abort Signals | ✅ | ✅ | ❌ | ❌ |\n| Web API Compatibility | ✅ | ❌ | ❌ | ❌ |\n\n## 🔗 Links\n\n- [Documentation](https://docs.rs/fetchttp)\n- [Repository](https://github.com/MuntasirSZN/fetchttp)\n- [Issues](https://github.com/MuntasirSZN/fetchttp/issues)\n- [WHATWG Fetch Specification](https://fetch.spec.whatwg.org/)\n\n---\n\nMade with ❤️ by [MuntasirSZN](https://github.com/MuntasirSZN)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuntasirszn%2Ffetchttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuntasirszn%2Ffetchttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuntasirszn%2Ffetchttp/lists"}