Skip to content

Commit f33d11e

Browse files
Use native fetch (#215)
* use native fetch * ci: add node 22 * ci: update matrix
1 parent 7de425f commit f33d11e

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
name: Tests
88
strategy:
99
matrix:
10-
node-version: [18.x, 20.x]
10+
node-version: [20.x, 22.x, 24.x]
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout sources

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
"get-youtube-chapters": "^2.0.0",
1313
"get-youtube-id": "^1.0.0",
1414
"http-errors": "^2.0.0",
15-
"node-fetch": "^2.6.0",
1615
"parse-iso-duration": "^1.1.0"
1716
},
1817
"devDependencies": {
1918
"@types/http-errors": "^2.0.0",
20-
"@types/node-fetch": "^2.5.4",
2119
"@types/qs": "^6.9.4",
2220
"dprint": "^0.50.0",
2321
"nock": "^14.0.0",

src/Client.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import createError from 'http-errors';
2-
import https from 'https';
3-
import fetch from 'node-fetch';
42

53
/**
64
* General interface for query parameters to the YouTube API.
@@ -507,16 +505,13 @@ export type ListChannelsOptions = RequestOptions & ({ forUsername: string } | {
507505
export default class YouTubeClient {
508506
private params: Params;
509507

510-
private agent: https.Agent;
511-
512508
private baseUrl = 'https://www.googleapis.com/youtube/v3';
513509

514510
/**
515511
* @param params Default query parameters for YouTube API requests—typically for API keys.
516512
*/
517513
constructor(params: Params) {
518514
this.params = params;
519-
this.agent = new https.Agent({ keepAlive: true });
520515
}
521516

522517
private async get<TResponse>(resource: string, options: Params): Promise<TResponse> {
@@ -526,9 +521,7 @@ export default class YouTubeClient {
526521
.map(([key, value]) => [key, String(value)]),
527522
);
528523
const query = new URLSearchParams(params);
529-
const response = await fetch(`${this.baseUrl}/${resource}?${query}`, {
530-
agent: this.agent,
531-
});
524+
const response = await fetch(`${this.baseUrl}/${resource}?${query}`);
532525
const data = await response.json();
533526
if (!response.ok) {
534527
throw createError(response.status, data.error.message);

0 commit comments

Comments
 (0)