{"id":21524874,"url":"https://github.com/degjs/fetchutils","last_synced_at":"2025-04-09T23:11:08.064Z","repository":{"id":36869390,"uuid":"41176362","full_name":"DEGJS/fetchUtils","owner":"DEGJS","description":"A utility library for using the Fetch API.","archived":false,"fork":false,"pushed_at":"2023-01-04T14:54:28.000Z","size":1601,"stargazers_count":10,"open_issues_count":4,"forks_count":1,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-09T23:11:02.798Z","etag":null,"topics":["utility"],"latest_commit_sha":null,"homepage":"http://degjs.com/fetchUtils/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DEGJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-21T20:35:12.000Z","updated_at":"2025-02-06T04:16:23.000Z","dependencies_parsed_at":"2023-01-17T06:12:53.329Z","dependency_job_id":null,"html_url":"https://github.com/DEGJS/fetchUtils","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FfetchUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FfetchUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FfetchUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DEGJS%2FfetchUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DEGJS","download_url":"https://codeload.github.com/DEGJS/fetchUtils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125603,"owners_count":21051770,"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","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":["utility"],"created_at":"2024-11-24T01:30:10.416Z","updated_at":"2025-04-09T23:11:08.037Z","avatar_url":"https://github.com/DEGJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetchUtils\n\nFetchUtils is a utility module that adds the following features to the Javascript [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API):\n+ Request timeouts, which the Fetch API currently lacks\n+ Helper methods for requesting and parsing a JSON- or HTML-encoded response data from an endpoint \n\n## Demo\nYou can view a demo of fetchUtils [here](http://degjs.github.io/fetchUtils/).\n\n## Install\nAs of version 3.0.0, fetchUtils is on NPM and can be installed with \n```\nnpm install @degjs/fetch-utils\n```\n\n## Usage\nFetchUtils is a singleton, so it does not need to be instantiated.\n```js\nimport fetchUtils from \"@degjs/fetch-utils\";\n\n/* Success handler */\nfunction onSuccess(data) {\n    console.log(\"SUCCESS: \" + data);\n}\n\n/* Error handler */\nfunction onError(error) {\n    console.log(\"ERROR: \" + error);\n}\n\n/* Perform a GET request with a 30-second timeout and expect a JSON-encoded response */\nlet fetchParams = {\n\tmethod: 'GET',\n\tbody: {}\n};\n\nlet options = {\n\ttimeout: 30000\n};\n\nfetchUtils.getJSON('/endpoint-url', fetchParams, options)\n    .then(onSuccess)\n    .catch(onError);\n\n```\n\n## Methods\n\n### .getHTML(url [, fetchParams [, options]])\nReturns: `Promise`   \nPerform a request to an endpoint that returns HTML-encoded data. Sets the `Accept` option on request header to `text/html`.\n\n### .getJSON(url [, fetchParams [, options]])\nReturns: `Promise`   \nPerform a request to an endpoint that returns JSON-encoded data. Sets the `Accept` option on request header to `application/json`.\n\n### .fetch(url [, fetchParams [, options]])\nReturns: `Promise`   \nPerform a request to an endpoint that returns the full, unparsed endpoint response.\n\nThe parameters for the `.getHTML()`, `.getJSON()` and `.fetch()` methods are outlined below:\n\n#### url\nType: `String`   \nThe URL of the endpoint. This parameter is required.\n\n#### fetchParams\nType: `Object`   \nRequest options (such as method, body, etc.) that are passed through to the `fetch()` method. These options correspond to those defined in the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch#Syntax). This parameter is optional.\n\n#### options\nType: `Object`   \nAdditional options that fall outside of the Fetch API. This parameter is optional.\n\n##### options.timeout\nType: `Number`   \nThe number of milliseconds that the request should wait before timing out. The default timeout value is 10,000 millseconds (10 seconds). \n\n### .setCallback(functionName)\nDefine a callback function that will be executed on fetch success. This is not recommended in most scenarios (use `.then()` and `.catch()` from the returned promise instead), but may be useful in specific situations.\n\n### .setOptions(options)\nOverride default plugin options, such as `timeout` and `cachebusting`. Must be called before any of the fetch methods above are called.\n\n\n## Browser Support\nFetchUtils depends on the following browser APIs:\n+ [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch)\n+ [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n+ [Object.assign](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)\n\nTo support legacy browsers, you'll need to include polyfills for the above APIs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Ffetchutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdegjs%2Ffetchutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegjs%2Ffetchutils/lists"}