{"id":19123019,"url":"https://github.com/digitalbazaar/http-client","last_synced_at":"2025-05-05T18:30:22.118Z","repository":{"id":39988861,"uuid":"271297950","full_name":"digitalbazaar/http-client","owner":"digitalbazaar","description":"An opinionated, isomorphic HTTP client.","archived":false,"fork":false,"pushed_at":"2025-03-26T01:03:23.000Z","size":99,"stargazers_count":2,"open_issues_count":11,"forks_count":7,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-03-26T01:36:09.494Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-10T14:24:12.000Z","updated_at":"2023-04-06T22:29:25.000Z","dependencies_parsed_at":"2024-01-26T02:25:59.368Z","dependency_job_id":"e68f186b-e80e-49aa-ac32-da3a33704162","html_url":"https://github.com/digitalbazaar/http-client","commit_stats":{"total_commits":123,"total_committers":8,"mean_commits":15.375,"dds":0.6422764227642277,"last_synced_commit":"ab5662873e00468f530706a05434bbaffd8730b1"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fhttp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fhttp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fhttp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fhttp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/http-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249600251,"owners_count":21297664,"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":[],"created_at":"2024-11-09T05:23:57.749Z","updated_at":"2025-04-19T03:31:33.122Z","avatar_url":"https://github.com/digitalbazaar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-client\nAn opinionated, isomorphic HTTP client for Node.js, browsers, and React Native.\n\n### Usage\n\n#### Import httpClient (Node.js)\n```js\nimport https from 'https';\nimport {httpClient} from '@digitalbazaar/http-client';\n```\n\n#### Import httpClient (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 httpsAgent = new https.Agent({rejectUnauthorized: false});\n\nconst accessToken = '12345';\nconst headers = {Authorization: `Bearer ${accessToken}`};\n\nconst client = httpClient.extend({headers, httpsAgent});\n\n// subsequent http calls will include an 'Authorization: Bearer 12345' header,\n// and use the provided httpsAgent\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fhttp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fhttp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fhttp-client/lists"}