{"name":"@digitalbazaar/http-client","version":"4.2.0","keywords":["http","isomorphic","http client"],"author":{"url":"https://digitalbazaar.com/","name":"Digital Bazaar, Inc.","email":"support@digitalbazaar.com"},"license":"BSD-3-Clause","_id":"@digitalbazaar/http-client@4.2.0","maintainers":[{"name":"dlongley","email":"dlongley@digitalbazaar.com"},{"name":"msporny","email":"msporny@digitalbazaar.com"},{"name":"davidlehn","email":"dil@lehn.org"},{"name":"gannan","email":"gannan@digitalbazaar.com"}],"homepage":"https://github.com/digitalbazaar/http-client","bugs":{"url":"https://github.com/digitalbazaar/http-client/issues"},"c8":{"reporter":["lcov","text-summary","text"]},"dist":{"shasum":"eeaafdf1b1653d87ef2d985aa0da1e8d34f5f7c9","tarball":"http://registry-npm.ywwl.com/@digitalbazaar/http-client/download/@digitalbazaar/http-client-4.2.0.tgz","fileCount":9,"integrity":"sha512-OGju/GYp0V72qlZ/Pd4jGEwqBwT/Za/tw+Z3AC7lgMheGqsbhTZrtc5iLz9z59G/Q53QyE2fnjHV8N9wjBpiWA==","signatures":[{"sig":"MEYCIQC674cOmKAiAmUCIDb/vKh1swV7iB3VLud5NfEbI8s58QIhAJy6srL6VuR6Z6n36Ut7K3W4xvwja6iQziGrP0/ZNujF","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20950,"size":5319,"noattachment":false,"key":"/@digitalbazaar/http-client/-/@digitalbazaar/http-client-4.2.0.tgz"},"main":"./dist/cjs/index.cjs","type":"module","browser":{"./tests/utils.cjs":"./tests/utils-browser.cjs","./lib/agentCompatibility.js":"./lib/agentCompatibility-browser.js"},"engines":{"node":">=18.0"},"exports":{"import":"./lib/index.js","require":"./dist/cjs/index.cjs"},"gitHead":"7d0fb038a4e6e1c04d01b60e1c42ccbb583f232e","scripts":{"lint":"eslint --ext .cjs,.js --ignore-pattern rollup.config.js .","test":"npm run test-node && npm run test-node-cjs","build":"npm run clear && npm run rollup","clear":"rimraf dist/ && mkdir dist","rollup":"rollup -c rollup.config.js","prepare":"npm run build","rebuild":"npm run clear && npm run build","coverage":"cross-env NODE_ENV=test c8 npm run test-node","test-node":"cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js","test-karma":"karma start karma.conf.cjs","test-watch":"cross-env NODE_ENV=test mocha --watch --parallel --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.js tests/*.spec.js","coverage-ci":"cross-env NODE_ENV=test c8 --reporter=lcovonly --reporter=text-summary --reporter=text npm run test-node","test-node-cjs":"cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require tests/test-mocha.cjs tests/*.spec.cjs","coverage-report":"c8 report"},"_npmUser":{"name":"davidlehn","email":"dil@lehn.org"},"repository":{"url":"git+https://github.com/digitalbazaar/http-client.git","type":"git"},"_npmVersion":"10.9.2","description":"An opinionated, isomorphic HTTP client.","directories":{},"_nodeVersion":"20.13.0","dependencies":{"ky":"^1.7.5","undici":"^6.21.2"},"react-native":{"./lib/agentCompatibility.js":"./lib/agentCompatibility-browser.js"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","chai":"^4.5.0","cors":"^2.8.5","karma":"^6.4.4","mocha":"^11.1.0","eslint":"^8.57.1","rimraf":"^6.0.1","rollup":"^4.37.0","express":"^4.21.2","webpack":"^5.98.0","cross-env":"^7.0.3","karma-chai":"^0.1.0","detect-node":"^2.1.0","karma-mocha":"^2.0.1","karma-webpack":"^5.0.1","eslint-plugin-jsdoc":"^50.6.9","karma-mocha-reporter":"^2.2.5","eslint-plugin-unicorn":"^56.0.1","karma-chrome-launcher":"^3.2.0","karma-sourcemap-loader":"^0.4.0","eslint-config-digitalbazaar":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/http-client_4.2.0_1742955325729_0.46954575621124794","host":"s3://npm-registry-packages-npm-production"},"readme":"# http-client\nAn opinionated, isomorphic HTTP client for Node.js, browsers, and React Native.\n\n### Usage\n\n#### Import httpClient (Node.js, browsers, or React Native)\n```js\nimport {httpClient} from '@digitalbazaar/http-client';\n```\n\n#### Import and initialize a custom Bearer Token client\n```js\nimport {httpClient} from '@digitalbazaar/http-client';\n\nconst accessToken = '12345';\nconst headers = {Authorization: `Bearer ${accessToken}`};\n\nconst client = httpClient.extend({headers});\n\n// subsequent http calls will include an 'Authorization: Bearer 12345' header\n```\n\n#### Disable self-signed TLS/SSL cert checks for development purposes only\n```js\nimport {Agent} from 'https';\nimport {httpClient} from '@digitalbazaar/http-client';\n\nconst agent = new https.Agent({rejectUnauthorized: false});\nconst client = httpClient.extend({headers, agent});\n\n// subsequent http calls will use the provided https Agent\n```\n\n#### GET a JSON response in the browser\n```js\ntry {\n  const response = await httpClient.get('http://httpbin.org/json');\n  return response.data;\n} catch(e) {\n  // status is HTTP status code\n  // data is JSON error from the server\n  const {data, status} = e;\n  throw e;\n}\n```\n\n#### GET a JSON response in Node with an HTTP Agent\n```js\nimport https from 'https';\n// use an agent to avoid self-signed certificate errors\nconst agent = new https.Agent({rejectUnauthorized: false});\ntry {\n  const response = await httpClient.get('http://httpbin.org/json', {agent});\n  return response.data;\n} catch(e) {\n  // status is HTTP status code\n  // data is JSON error from the server if available\n  const {data, status} = e;\n  throw e;\n}\n```\n\n#### GET HTML by overriding default headers\n```js\nconst headers = {Accept: 'text/html'};\ntry {\n  const response = await httpClient.get('http://httpbin.org/html', {headers});\n  // see: https://developer.mozilla.org/en-US/docs/Web/API/Response#methods\n  return response.text();\n} catch(e) {\n  // status is HTTP status code\n  // any message from the server can be parsed from the response if present\n  const {response, status} = e;\n  throw e;\n}\n```\n\n#### POST a JSON payload\n```js\ntry {\n  const response = await httpClient.post('http://httpbin.org/json', {\n    // `json` is the payload or body of the POST request\n    json: {some: 'data'}\n  });\n  return response.data;\n} catch(e) {\n  // status is HTTP status code\n  // data is JSON error from the server\n  const {data, status} = e;\n  throw e;\n}\n```\n\n#### POST a JSON payload in Node with an HTTP Agent\n```js\nimport https from 'https';\n// use an agent to avoid self-signed certificate errors\nconst agent = new https.Agent({rejectUnauthorized: false});\ntry {\n  const response = await httpClient.post('http://httpbin.org/json', {\n    agent,\n    // `json` is the payload or body of the POST request\n    json: {some: 'data'}\n  });\n  return response.data;\n} catch(e) {\n  // status is HTTP status code\n  // data is JSON error from the server\n  const {data, status} = e;\n  throw e;\n}\n```\n","publish_time":1742955325950,"_cnpm_publish_time":1742955325950,"dist-tags":{"latest":"4.4.0"}}