{"id":13781536,"url":"https://github.com/thinkjs/think-fetch","last_synced_at":"2025-08-01T11:35:12.724Z","repository":{"id":71953223,"uuid":"86650127","full_name":"thinkjs/think-fetch","owner":"thinkjs","description":"Fetch for ThinkJS 3.x","archived":false,"fork":false,"pushed_at":"2020-09-10T18:02:41.000Z","size":16,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-06T22:42:00.420Z","etag":null,"topics":["fetch","think-extend","thinkjs3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/thinkjs.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}},"created_at":"2017-03-30T02:30:02.000Z","updated_at":"2020-08-22T01:45:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb3ad1c4-419c-4d24-8d49-eabd011d85d2","html_url":"https://github.com/thinkjs/think-fetch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/thinkjs/think-fetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkjs","download_url":"https://codeload.github.com/thinkjs/think-fetch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkjs%2Fthink-fetch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268215611,"owners_count":24214365,"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-08-01T02:00:08.611Z","response_time":67,"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":["fetch","think-extend","thinkjs3"],"created_at":"2024-08-03T18:01:26.885Z","updated_at":"2025-08-01T11:35:12.699Z","avatar_url":"https://github.com/thinkjs.png","language":"JavaScript","readme":"# think-fetch\n[![npm](https://img.shields.io/npm/v/think-fetch.svg)](https://www.npmjs.com/package/think-fetch)\n[![Build Status](https://travis-ci.org/thinkjs/think-fetch.svg?branch=master)](https://travis-ci.org/thinkjs/think-fetch)\n[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-fetch/badge.svg?branch=master)](https://coveralls.io/github/thinkjs/think-fetch?branch=master)\n\nFetch for ThinkJS 3.x\n\n## Install\n\n```\n$ npm install think-fetch --save\n```\n\n## How to use\n\nconfig file `src/config/extend.js`\n\n```javascript\nconst fetch = require('think-fetch');\n\nmodule.exports = [\n  fetch, // HTTP request client.\n];\n```\n\n## Methods in Controller\n\n```javascript\nmodule.exports = class extends think.Controller {\n  async indexAction () {\n\n    // plain text or html\n    const text = await this.fetch('https://github.com/').then(res =\u003e res.text());\n\n    // json\n    const json = await this.fetch('https://api.github.com/repos/thinkjs/think-fetch').then(res =\u003e res.json());\n\n    // post\n    const body = await this.fetch('http://httpbin.org/post', { method: 'POST', body: 'a=1' }).then(res =\u003e res.json());\n\n    // stream\n    const res = await this.fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png');\n    const dest = fs.createWriteStream('./octocat.png');\n    res.body.pipe(dest);\n\n    // post with stream from file\n    const stream = fs.createReadStream('input.txt');\n    const result = this.fetch('http://httpbin.org/post', { method: 'POST', body: stream }).then(res =\u003e res.json());\n  }\n}\n```\n\n## API\n\n### fetch(url[, options])\n\n- `url` A string representing the URL for fetching\n- `options` [Options](#options) for the HTTP(S) request\n- Returns: `Promise\u003cResponse\u003e`\n\nPerform an HTTP(S) fetch.\n\nurl should be an absolute url, such as `http://example.com/`. A path-relative URL (`/file/under/root`) or protocol-relative URL (`//can-be-http-or-https.com/`) will result in a rejected promise.\n\n#### Options\n\nThe default values are shown after each option key.\n\n```javascript\n{\n  // These properties are part of the Fetch Standard\n  method: 'GET',\n  headers: {},        // request headers. format is the identical to that accepted by the Headers constructor (see below)\n  body: null,         // request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream\n  redirect: 'follow', // set to `manual` to extract redirect headers, `error` to reject redirect\n\n  // The following properties are node-fetch extensions\n  follow: 20,         // maximum redirect count. 0 to not follow redirect\n  timeout: 0,         // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)\n  compress: true,     // support gzip/deflate content encoding. false to disable\n  size: 0,            // maximum response body size in bytes. 0 to disable\n  agent: null         // http(s).Agent instance, allows custom proxy, certificate etc.\n}\n```\n\n##### Default Headers\n\nIf no values are set, the following request headers will be sent automatically:\n\n| Header | Value |\n| :------: | :------: |\n| `Accept-Encoding` | `gzip,deflate` (when `options.compress === true`) |\n| `Accept` | `*/*` |\n| `Connection` | `close` (when no `options.agent` is present) |\n| `Content-Length` | (automatically calculated, if possible) |\n| `User-Agent` | `node-fetch/1.0 (+https://github.com/bitinn/node-fetch)` |\n\n\n\n[More Methods Click](https://github.com/bitinn/node-fetch)","funding_links":[],"categories":["Extends"],"sub_categories":["websocket"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkjs%2Fthink-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkjs%2Fthink-fetch/lists"}