digitalbazaar / http-client

An opinionated, isomorphic HTTP client.
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

Implement a customClient() wrapper. #13

Closed dmitrizagidulin closed 2 years ago

dmitrizagidulin commented 3 years ago

Creates a lightweight wrapper around httpClient that adds bearer token Authorization headers.

codecov-commenter commented 3 years ago

Codecov Report

Merging #13 (e04b371) into main (ac47d32) will increase coverage by 0.71%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
+ Coverage   94.28%   95.00%   +0.71%     
==========================================
  Files           2        2              
  Lines          35       40       +5     
==========================================
+ Hits           33       38       +5     
  Misses          2        2              
Impacted Files Coverage Δ
main.js 94.73% <100.00%> (+0.79%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ac47d32...e04b371. Read the comment docs.

dmitrizagidulin commented 2 years ago

It seems like this could be generalized to instead allow a different set of default headers / overrides be passed. Then it could be used for any header(s), not just Bearer. It may also be possible to implement that more simply by having an internal property for it that can be updated vs. having to do (another) proxy wrapper.

@dlongley - refactored. Usage is now generic (the options to customClient are passed through to ky.create()):

import {customClient} from `@digitalbazaar/http-client`;

const headers = {Authorization: `Bearer ${accessToken}`};
const httpClient = customClient({headers, httpsAgent});