{"_id":"@austinbreslin/fetcher","name":"@austinbreslin/fetcher","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"$schema":"https://json.schemastore.org/package.json","name":"@austinbreslin/fetcher","version":"1.0.0","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"dependencies":{"@austinbreslin/pledge":"1.0.1"},"license":"MIT","keywords":[],"repository":{"url":"git+https://github.com/AustinBreslinDev/libs/.git","type":"git"},"homepage":"https://github.com/AustinBreslinDev/libs/","engines":{"pnpm":">=9.15.2","node":">=20"},"scripts":{"build":"NODE_ENV=production rimraf ./dist && vite build && jampack ./dist","build:dev":"NODE_ENV=development vite build --mode development","dev":"NODE_ENV=development vite build --mode development --watch","lint":"tsc --noEmit && biome check ./src --config-path ../../biome.json","dev:lib":"NODE_ENV=development vite build --watch","test":"vitest","test:bench":"vitest bench","test:debug":"npm run test -- --inspect --no-file-parallelism --ui"},"_id":"@austinbreslin/fetcher@1.0.0","description":"<!--toc:start-->","_integrity":"sha512-nKRWlUtnqjhGa1cKLQwobDPGBHBlG+E81qibdsd+UR9UVOrqemnQa8V218vuydo6OkMIKmQ1PvlJ7B6eDPZ0sA==","_resolved":"/tmp/ee832909dac76a292e066e9bcee2ceb0/austinbreslin-fetcher-1.0.0.tgz","_from":"file:austinbreslin-fetcher-1.0.0.tgz","_nodeVersion":"22.12.0","_npmVersion":"11.0.0","dist":{"integrity":"sha512-nKRWlUtnqjhGa1cKLQwobDPGBHBlG+E81qibdsd+UR9UVOrqemnQa8V218vuydo6OkMIKmQ1PvlJ7B6eDPZ0sA==","shasum":"0c1aceecd6f02467ba5808c83bf8faaaa54a7b89","tarball":"https://registry.npmjs.org/@austinbreslin/fetcher/-/fetcher-1.0.0.tgz","fileCount":6,"unpackedSize":15162,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDPt6kVz3mSYGRUt7VMyzKQ3LmuA7dESN3kglVv35xUFwIgBsWLEln418j/YXMRHjKF9q1iRRpK09qY04m91iOyuN0="}]},"_npmUser":{"name":"austinbreslindev","email":"buckyaustin@gmail.com"},"directories":{},"maintainers":[{"name":"austinbreslindev","email":"buckyaustin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetcher_1.0.0_1736714892012_0.3473006630402271"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-12T20:48:11.912Z","1.0.0":"2025-01-12T20:48:12.173Z","modified":"2025-01-12T20:48:12.476Z"},"maintainers":[{"name":"austinbreslindev","email":"buckyaustin@gmail.com"}],"description":"<!--toc:start-->","homepage":"https://github.com/AustinBreslinDev/libs/","keywords":[],"repository":{"url":"git+https://github.com/AustinBreslinDev/libs/.git","type":"git"},"license":"MIT","readme":"# Fetcher: A wrapper around Fetch for convenience\n\n<!--toc:start-->\n\n- [Fetcher: A wrapper around Fetch for convenience](#fetcher-a-wrapper-around-fetch-for-convenience)\n  - [Why use fetcher?](#why-use-fetcher)\n    - [Simplicity](#simplicity)\n    - [Error Handling](#error-handling)\n    - [Features](#features)\n  - [Extra Features](#extra-features)\n    - [TypeScript Support](#typescript-support)\n    - [Modules](#modules)\n    - [Timeout option](#timeout-option)\n    - [Fetch implementation](#fetch-implementation)\n    - [JSON Parse implementation](#json-parse-implementation)\n    - [Installation](#installation)\n  - [Usage](#usage)\n  - [Dependencies](#dependencies)\n\n<!--toc:end-->\n\nFetcher is a library built on top of `fetch` API to make http requests in your web applications.\nIt provides similar APIs to `fetch`, but doesn't require as much boilerplate code.\n\n## Why use fetcher?\n\n### Simplicity\n\nFetcher makes it easier to perform HTTP requests in your JavaScript or TypeScript projects.\nIt abstracts away the complexities of the `fetch` API, allowing you to focus on writing your application's logic\nwithout worrying about low-level details. You also don't have to check if the HTTP Request was OK either.\n\n### Error Handling\n\nUnlike `fetch`, Fetcher doesn't throw errors. Instead, it resolves a promise with an error (if there is one)\nand the result of the request. This makes it easier to handle errors in your application's code.\n\n### Features\n\nFetcher supports all methods provided by the `fetch` API: `GET`, `POST`, `PUT`, `PATCH`, and `DELETE`.\nIt also supports response formats such as JSON, text, blob, bytes, form data, array buffer, and cloned responses.\nFetcher has more features than the fetch API.\n\n## Extra Features\n\n### TypeScript Support\n\nFetcher is fully supported in TypeScript, allowing you to take advantage of TypeScript's powerful type checking\nfeatures. This helps catch errors at compile time and makes your code more robust.\n\n### Modules\n\nFetcher is available as both CommonJS and ES modules, making it easy to use in a variety of project setups.\nThe packaged size is around 3kb, npm reports the TS definitions, both types of modules.\n\n### Timeout option\n\nFetcher has a timeout option available for all requests.\n\n```typescript\nimport { fetcher } from \"@austinbreslin/fetcher\";\n\n// One second time limit. If time excedes limit, error will have a value.\nconst [error, result] = await fetcher(\"https://example.com\", {\n    timeoutOptions: {\n        timeoutEnabled: true,\n        timeLimitMs: 1000 \n    }\n});\n```\n\n### Fetch implementation\n\nFetcher allows you to supply your own implementation of the Fetch API. The reason for this is because in\nNodeJS, you might have a scenario where you have to change some HTTP details for CORS or some other reason.\nFetcher doesn't want to prevent you from making an HTTP changes that you require.\n\nThere is a another effect of this, if you use an old version of NodeJS that doesn't have the Fetch API,\nyou can pass in a polyfilled implementation of that and still recieve all the goodnees of Fetcher.\nWhile possible, Fetcher cannot support that polyfill, as it could deviate from the Standard, so\nbe particular about your package selections, if there is a standard please try to find a package\nthat most accurately follows that standard.\n\n### JSON Parse implementation\n\nFetcher allows you to supply your own implementation of JSON parsing. This was added because the standard\nJSON parse built into browsers/NodeJS works funny at best. So you might want to use a different parser,\nsuch as `@austinbreslin/safe-json`\n\n### Installation\n\nYou can install Fetcher using npm:\n\n```terminal\nnpm install --save @austinbreslin/fetcher\n```\n\nOr pnpm:\n\n```terminal\npnpm install @austinbreslin/fetcher \n```\n\n## Usage\n\nHere's an example of how to use Fetcher to make a GET request:\n\n```typescript\nimport { fetcher } from '@austinbreslin/core-utils';\n\nconst [error, result] = await fetcher.get('https://jsonplaceholder.typicode.com/posts/1').json()\nconsole.log({ error, result });\n```\n\nThis will make a GET request to `https://jsonplaceholder.typicode.com/posts/1`,\nand print the response data to the console.\nIf there is an error, it will be logged to the console instead.\n\n## Dependencies\n\n- [Pledge](<>) - Wraps promises preventing a lot of boilerplate code\n","readmeFilename":"readme.md"}