{"id":20542212,"url":"https://github.com/weivea/fastify-curl","last_synced_at":"2026-06-06T11:31:07.145Z","repository":{"id":83302212,"uuid":"127119163","full_name":"weivea/fastify-curl","owner":"weivea","description":"httpRequest for fastify","archived":false,"fork":false,"pushed_at":"2018-03-28T09:55:21.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T04:29:25.295Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/weivea.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-28T09:46:04.000Z","updated_at":"2018-10-24T05:48:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"1e521e17-9adc-48d1-91dd-e095715a6c01","html_url":"https://github.com/weivea/fastify-curl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/fastify-curl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-curl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-curl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-curl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-curl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/fastify-curl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-curl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33981122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"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":[],"created_at":"2024-11-16T01:29:49.277Z","updated_at":"2026-06-06T11:31:07.124Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-curl\n\nfastify 框架的 httpclient  \n基于[urllib](https://github.com/node-modules/urllib)\n\n## install\n\n```\nnpm install fastify-curl --save\n```\n\n## usage\n\n详见[example](./example)\n\n```javascript\nconst fastify = require('fastify')()\nconst curl = require('fastify-curl')\nconst config = {\n  // ...详细信息见下方\n}\napp.register(curl, config)\n\n// Declare a route\nfastify.get('/', async function(request, reply) {\n  const option = {\n    // ...详细信息见下方\n  }\n  const re = await app.curl('http://xxxx', option)\n  console.log(re.data);\n  reply.send({ hello: 'world' })\n})\n\n// Run the server!\nfastify.listen(3000, '0.0.0.0', function(err) {\n  if (err) throw err\n  console.log(\n    `server listening on http://${fastify.server.address().address}:${\n      fastify.server.address().port\n    }`\n  )\n})\n```\n\n## config\n\n```javascript\n// default\n{\n  httpclient: {\n    request: {\n      timeout: 5000\n    },\n    httpAgent: {\n      keepAlive: true,\n      freeSocketKeepAliveTimeout: 4000,\n      maxSockets: 9007199254740991,\n      maxFreeSockets: 256\n    },\n    httpsAgent: {\n      keepAlive: true,\n      freeSocketKeepAliveTimeout: 4000,\n      maxSockets: 9007199254740991,\n      maxFreeSockets: 256\n    }\n  }\n}\n```\n\n## option\n\n* **_method_** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`. Alias 'type'.\n  * **_data_** Object - Data to be sent. Will be stringify automatically.\n  * **_dataAsQueryString_** Boolean - Force convert `data` to query string.\n  * **_content_** String | [Buffer](http://nodejs.org/api/buffer.html) - Manually set the content of payload. If set, `data` will be ignored.\n  * **_stream_** [stream.Readable](http://nodejs.org/api/stream.html#stream_class_stream_readable) - Stream to be pipe to the remote. If set, `data` and `content` will be ignored.\n  * **_writeStream_** [stream.Writable](http://nodejs.org/api/stream.html#stream_class_stream_writable) - A writable stream to be piped by the response stream. Responding data will be write to this stream and `callback` will be called with `data` set `null` after finished writing.\n  * **_consumeWriteStream_** [true] - consume the writeStream, invoke the callback after writeStream close.\n  * **_contentType_** String - Type of request data. Could be `json`. If it's `json`, will auto set `Content-Type: application/json` header.\n  * **_nestedQuerystring_** Boolean - urllib default use querystring to stringify form data which don't support nested object, will use [qs](https://github.com/ljharb/qs) instead of querystring to support nested object by set this option to true.\n  * **_dataType_** String - Type of response data. Could be `text` or `json`. If it's `text`, the `callback`ed `data` would be a String. If it's `json`, the `data` of callback would be a parsed JSON Object and will auto set `Accept: application/json` header. Default `callback`ed `data` would be a `Buffer`.\n  * **fixJSONCtlChars** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.\n  * **_headers_** Object - Request headers.\n  * **_timeout_** Number | Array - Request timeout in milliseconds for connecting phase and response receiving phase. Defaults to `exports.TIMEOUT`, both are 5s. You can use `timeout: 5000` to tell urllib use same timeout on two phase or set them seperately such as `timeout: [3000, 5000]`, which will set connecting timeout to 3s and response 5s.\n  * **_auth_** String - `username:password` used in HTTP Basic Authorization.\n  * **_digestAuth_** String - `username:password` used in HTTP [Digest Authorization](http://en.wikipedia.org/wiki/Digest_access_authentication).\n  * **_agent_** [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) - HTTP Agent object.\n    Set `false` if you does not use agent.\n  * **_httpsAgent_** [https.Agent](http://nodejs.org/api/https.html#https_class_https_agent) - HTTPS Agent object.\n    Set `false` if you does not use agent.\n  * **_ca_** String | Buffer | Array - An array of strings or Buffers of trusted certificates.\n    If this is omitted several well known \"root\" CAs will be used, like VeriSign.\n    These are used to authorize connections.\n    **Notes**: This is necessary only if the server uses the self-signed certificate\n  * **_rejectUnauthorized_** Boolean - If true, the server certificate is verified against the list of supplied CAs.\n    An 'error' event is emitted if verification fails. Default: true.\n  * **_pfx_** String | Buffer - A string or Buffer containing the private key,\n    certificate and CA certs of the server in PFX or PKCS12 format.\n  * **_key_** String | Buffer - A string or Buffer containing the private key of the client in PEM format.\n    **Notes**: This is necessary only if using the client certificate authentication\n  * **_cert_** String | Buffer - A string or Buffer containing the certificate key of the client in PEM format.\n    **Notes**: This is necessary only if using the client certificate authentication\n  * **_passphrase_** String - A string of passphrase for the private key or pfx.\n  * **_ciphers_** String - A string describing the ciphers to use or exclude.\n  * **_secureProtocol_** String - The SSL method to use, e.g. SSLv3_method to force SSL version 3.\n  * **_followRedirect_** Boolean - follow HTTP 3xx responses as redirects. defaults to false.\n  * **_maxRedirects_** Number - The maximum number of redirects to follow, defaults to 10.\n  * **_formatRedirectUrl_** Function - Format the redirect url by your self. Default is `url.resolve(from, to)`.\n  * **_beforeRequest_** Function - Before request hook, you can change every thing here.\n  * **_streaming_** Boolean - let you get the `res` object when request connected, default `false`. alias `customResponse`\n  * **_gzip_** Boolean - Accept gzip response content and auto decode it, default is `false`.\n  * **_timing_** Boolean - Enable timing or not, default is `false`.\n  * **_enableProxy_** Boolean - Enable proxy request, default is `false`.\n  * **_proxy_** String | Object - proxy agent uri or options, default is `null`.\n  * **_lookup_** Function - Custom DNS lookup function, default is `dns.lookup`. Require node \u003e= 4.0.0(for http protocol) and node \u003e=8(for https protocol)\n  * **_checkAddress_** Function: optional, check request address to protect from SSRF and similar attacks. It receive tow arguments(`ip` and `family`) and should return true or false to identified the address is legal or not. It rely on `lookup` and have the same version requirement.\n* **_callback(err, data, res)_** Function - Optional callback.\n  * **err** Error - Would be `null` if no error accured.\n  * **data** Buffer | Object - The data responsed. Would be a Buffer if `dataType` is set to `text` or an JSON parsed into Object if it's set to `json`.\n  * **res** [http.IncomingMessage](http://nodejs.org/api/http.html#http_http_incomingmessage) - The response.\n\nsee details from https://github.com/node-modules/urllib\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-curl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Ffastify-curl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-curl/lists"}