{"id":33380309,"url":"https://github.com/stevenrugg/curlhelper","last_synced_at":"2025-11-23T02:03:17.830Z","repository":{"id":325534554,"uuid":"1078996506","full_name":"stevenrugg/curlhelper","owner":"stevenrugg","description":"A powerful, curl-like HTTP client for JavaScript and TypeScript. A cURL helper library built on top of native fetch API with no dependencies. Easier to use than cURL, fetch, axios and XMLHttpRequest","archived":false,"fork":false,"pushed_at":"2025-10-18T21:38:54.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-21T23:17:14.700Z","etag":null,"topics":["api","chainable","chainable-methods","client","curl","curl-commands","curl-functions","curl-library","curlrequest","fetch","helper-functions","helper-tool","http","https","request","rest","restful-api","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/curlhelper","language":"TypeScript","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/stevenrugg.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-10-18T21:33:02.000Z","updated_at":"2025-10-18T21:47:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stevenrugg/curlhelper","commit_stats":null,"previous_names":["stevenrugg/curlhelper"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/stevenrugg/curlhelper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenrugg%2Fcurlhelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenrugg%2Fcurlhelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenrugg%2Fcurlhelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenrugg%2Fcurlhelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenrugg","download_url":"https://codeload.github.com/stevenrugg/curlhelper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenrugg%2Fcurlhelper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285889732,"owners_count":27248885,"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-11-23T02:00:06.149Z","response_time":135,"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":["api","chainable","chainable-methods","client","curl","curl-commands","curl-functions","curl-library","curlrequest","fetch","helper-functions","helper-tool","http","https","request","rest","restful-api","typescript"],"created_at":"2025-11-23T02:03:13.452Z","updated_at":"2025-11-23T02:03:17.823Z","avatar_url":"https://github.com/stevenrugg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CurlHelper\n\n\u003e A powerful, curl-like HTTP client for JavaScript and TypeScript\n\n[![npm version](https://img.shields.io/npm/v/curlhelper.svg)](https://www.npmjs.com/package/curlhelper)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**CurlHelper** is an intuitive HTTP client that brings the simplicity of curl to JavaScript/TypeScript with a modern, chainable API. Whether you're making simple GET requests or handling complex workflows, CurlHelper makes it effortless.\n\n## ✨ Key Features\n\n- 🔗 **Fluent Chainable API** - Natural, readable syntax for building requests\n- 🎯 **Curl Command Parser** - Paste curl commands directly and execute them\n- 📘 **Full TypeScript Support** - Complete type safety with generics\n- ⚡ **Built on Native Fetch** - Modern, performant, zero dependencies\n- 🔄 **Automatic Retries** - Smart retry logic with exponential backoff\n- 🎭 **Request/Response Interceptors** - Middleware-like functionality\n- 📊 **Request Timing** - Built-in performance metrics\n- 🎨 **Intuitive API** - Designed to feel like curl but JavaScript-native\n\n## 📦 Installation\n\n```bash\nnpm install curlhelper\n```\n\n```bash\nyarn add curlhelper\n```\n\n```bash\npnpm add curlhelper\n```\n\n## 🚀 Quick Start\n\n### Simple GET Request\n\n```typescript\nimport curl from 'curlhelper';\n\nconst response = await curl('https://api.github.com/users/octocat').get();\nconsole.log(response.data);\n```\n\n### POST with JSON\n\n```typescript\nconst user = await curl('https://api.example.com/users')\n  .json({ name: 'John Doe', email: 'john@example.com' })\n  .post();\n```\n\n### Chainable API\n\n```typescript\nconst response = await curl('https://api.example.com/data')\n  .header('Authorization', 'Bearer token')\n  .query({ page: 1, limit: 10 })\n  .timeout(5000)\n  .retry(3)\n  .get();\n```\n\n## 🎯 Parse Curl Commands (Ingenious Feature!)\n\nConvert curl commands directly to JavaScript:\n\n```typescript\nimport { fromCurl } from 'curlhelper';\n\nconst response = await fromCurl(`\n  curl -X POST https://api.github.com/repos/owner/repo/issues \\\n    -H \"Accept: application/vnd.github+json\" \\\n    -H \"Authorization: Bearer ghp_token\" \\\n    -d '{\"title\":\"Bug report\",\"body\":\"Found a bug\"}'\n`).post();\n```\n\nOr parse without executing:\n\n```typescript\nconst config = fromCurl.parse('curl -X GET https://api.example.com/users');\nconsole.log(config); // { url: '...', method: 'GET', headers: {...} }\n```\n\n## 📖 API Documentation\n\n### Creating Requests\n\n```typescript\n// Builder pattern\nconst builder = curl('https://api.example.com/endpoint');\n\n// Shorthand methods\nawait curl.get('https://api.example.com/users');\nawait curl.post('https://api.example.com/users', { name: 'John' });\nawait curl.put('https://api.example.com/users/1', { name: 'Jane' });\nawait curl.patch('https://api.example.com/users/1', { age: 30 });\nawait curl.delete('https://api.example.com/users/1');\n```\n\n### Builder Methods\n\n#### Headers\n\n```typescript\n// Single header\ncurl('https://api.example.com')\n  .header('X-API-Key', 'secret')\n  .get();\n\n// Multiple headers\ncurl('https://api.example.com')\n  .headers({\n    'X-API-Key': 'secret',\n    'X-Custom': 'value'\n  })\n  .get();\n```\n\n#### Authentication\n\n```typescript\n// Basic Auth\ncurl('https://api.example.com')\n  .auth('username', 'password')\n  .get();\n\n// Bearer Token\ncurl('https://api.example.com')\n  .bearer('your-token-here')\n  .get();\n```\n\n#### Query Parameters\n\n```typescript\ncurl('https://api.example.com/search')\n  .query({ q: 'javascript', page: 1, limit: 20 })\n  .get();\n// → https://api.example.com/search?q=javascript\u0026page=1\u0026limit=20\n```\n\n#### Request Body\n\n```typescript\n// JSON (automatic Content-Type)\ncurl('https://api.example.com/users')\n  .json({ name: 'John', age: 30 })\n  .post();\n\n// Form Data\ncurl('https://api.example.com/login')\n  .form({ username: 'john', password: 'secret' })\n  .post();\n```\n\n#### File Uploads\n\n```typescript\n// Upload files\ncurl('https://api.example.com/upload')\n  .file('avatar', './photo.jpg')\n  .file('document', fileBuffer, 'doc.pdf')\n  .post();\n\n// With additional fields\ncurl('https://api.example.com/upload')\n  .json({ userId: 123 })\n  .file('avatar', './photo.jpg')\n  .post();\n```\n\n#### Timeout \u0026 Retries\n\n```typescript\n// Set timeout\ncurl('https://api.example.com')\n  .timeout(5000) // 5 seconds\n  .get();\n\n// Automatic retries with exponential backoff\ncurl('https://api.example.com')\n  .retry(3, {\n    backoff: 'exponential',\n    delay: 1000,\n    maxDelay: 30000,\n    onRetry: (attempt, error) =\u003e {\n      console.log(`Retry attempt ${attempt}:`, error.message);\n    }\n  })\n  .get();\n```\n\n### TypeScript Support\n\n```typescript\ninterface User {\n  id: number;\n  name: string;\n  email: string;\n}\n\n// Response is typed as User\nconst response = await curl\u003cUser\u003e('https://api.example.com/users/1').get();\nconsole.log(response.data.name); // TypeScript knows this is a string\n\n// Array of Users\nconst users = await curl\u003cUser[]\u003e('https://api.example.com/users').get();\n```\n\n### Response Object\n\n```typescript\nconst response = await curl('https://api.example.com').get();\n\n// Response properties\nresponse.data       // Parsed response body\nresponse.status     // HTTP status code (200, 404, etc.)\nresponse.statusText // HTTP status text ('OK', 'Not Found', etc.)\nresponse.headers    // Response headers (Headers object)\nresponse.ok         // true if status is 200-299\nresponse.timing     // Performance metrics\nresponse.raw        // Original fetch Response object\n```\n\n### Interceptors\n\nAdd global middleware for all requests and responses:\n\n```typescript\n// Request interceptor\ncurl.interceptors.request.use((config) =\u003e {\n  // Add timestamp to all requests\n  config.headers.set('X-Request-Time', Date.now().toString());\n  return config;\n});\n\n// Response interceptor\ncurl.interceptors.response.use((response) =\u003e {\n  // Log all responses\n  console.log(`${response.status} - ${response.timing.total}ms`);\n  return response;\n});\n\n// Remove interceptor\nconst id = curl.interceptors.request.use(myInterceptor);\ncurl.interceptors.request.eject(id);\n```\n\n## 🎨 Advanced Examples\n\n### Parallel Requests\n\n```typescript\nconst [users, posts, comments] = await Promise.all([\n  curl('https://api.example.com/users').get(),\n  curl('https://api.example.com/posts').get(),\n  curl('https://api.example.com/comments').get(),\n]);\n```\n\n### Conditional Requests\n\n```typescript\nconst response = await curl('https://api.example.com/data')\n  .header('If-None-Match', etag)\n  .get();\n\nif (response.status === 304) {\n  console.log('Data not modified, use cache');\n}\n```\n\n### Streaming Responses\n\n```typescript\nconst response = await curl('https://api.example.com/large-file')\n  .stream()\n  .get();\n\n// response.data is the raw Response object with body stream\nconst reader = response.data.body.getReader();\n```\n\n### Abort Requests\n\n```typescript\nconst controller = new AbortController();\n\n// Abort after 3 seconds\nsetTimeout(() =\u003e controller.abort(), 3000);\n\ntry {\n  await curl('https://api.example.com/slow')\n    .abort(controller.signal)\n    .get();\n} catch (error) {\n  console.log('Request aborted');\n}\n```\n\n### Error Handling\n\n```typescript\ntry {\n  const response = await curl('https://api.example.com/users').get();\n\n  if (!response.ok) {\n    console.error(`HTTP Error: ${response.status}`);\n  }\n} catch (error) {\n  console.error('Request failed:', error);\n}\n```\n\n## 🔄 Comparison with Other Libraries\n\n### vs. Fetch\n\n```typescript\n// Native Fetch\nconst response = await fetch('https://api.example.com/users', {\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Authorization': 'Bearer token'\n  },\n  body: JSON.stringify({ name: 'John' })\n});\nconst data = await response.json();\n\n// CurlHelper\nconst { data } = await curl('https://api.example.com/users')\n  .bearer('token')\n  .json({ name: 'John' })\n  .post();\n```\n\n### vs. Axios\n\n```typescript\n// Axios\nconst response = await axios.post('https://api.example.com/users',\n  { name: 'John' },\n  { headers: { 'Authorization': 'Bearer token' } }\n);\n\n// CurlHelper\nconst response = await curl('https://api.example.com/users')\n  .bearer('token')\n  .json({ name: 'John' })\n  .post();\n```\n\n## 🏗️ Architecture\n\nCurlHelper is built with:\n\n- **Zero runtime dependencies** - Only uses native Web APIs\n- **TypeScript first** - Fully typed from the ground up\n- **Tree-shakeable** - Import only what you need\n- **Modern bundling** - ESM and CJS support\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\nMIT © Steven Rugg | stevenrugg.dev\n\n## 🙏 Acknowledgments\n\nInspired by the simplicity of curl and the elegance of modern JavaScript.\n\n---\n\nMade with ❤️ for developers who love clean APIs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenrugg%2Fcurlhelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenrugg%2Fcurlhelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenrugg%2Fcurlhelper/lists"}