Skip to content

Commit cc1cf02

Browse files
committed
Merge remote-tracking branch 'dlackty/remove-axios' into v3
2 parents a6349af + 0484706 commit cc1cf02

File tree

5 files changed

+296
-172
lines changed

5 files changed

+296
-172
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"parser": "babel-eslint",
33
"extends": "airbnb/base",
44
"env": {
5-
"mocha": true
5+
"mocha": true,
6+
"browser": true
67
},
78
"rules": {
89
"no-unused-expressions": "off"

.github/workflows/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
- 22
1111
- 20
1212
- 18
13-
- 14
14-
- 12
15-
- 10
1613
name: Node ${{ matrix.node-version }} sample
1714
steps:
1815
- uses: actions/checkout@v3

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
"url": "https://github.com/detectlanguage/detectlanguage-node/issues"
3636
},
3737
"homepage": "https://github.com/detectlanguage/detectlanguage-node",
38-
"dependencies": {
39-
"axios": "^0.21.1"
40-
},
4138
"devDependencies": {
4239
"@babel/cli": "^7.11.6",
4340
"@babel/core": "^7.11.6",

src/client.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import axios from 'axios';
21
import * as defaults from './defaults';
32
import { handleError } from './error';
43

@@ -11,28 +10,42 @@ export default class Client {
1110
Authorization: `Bearer ${apiKey}`,
1211
};
1312

14-
this.connection = axios.create({
15-
headers,
16-
baseURL: `${config.protocol}://${config.host}/${config.apiVersion}/`,
17-
timeout: config.timeout * 1000,
18-
});
13+
this.baseURL = `${config.protocol}://${config.host}/${config.apiVersion}/`;
14+
this.timeout = config.timeout * 1000;
15+
this.headers = headers;
1916
}
2017

2118
async get(path) {
2219
try {
23-
const response = await this.connection.get(path);
20+
const response = await fetch(this.baseURL + path, {
21+
headers: this.headers,
22+
timeout: this.timeout,
23+
});
2424

25-
return response.data;
25+
if (!response.ok) {
26+
throw new Error(await response.text());
27+
}
28+
29+
return await response.json();
2630
} catch (e) {
2731
return handleError(e);
2832
}
2933
}
3034

3135
async post(path, data) {
3236
try {
33-
const response = await this.connection.post(path, data);
37+
const response = await fetch(this.baseURL + path, {
38+
method: 'POST',
39+
headers: Object.assign(this.headers, { 'Content-Type': 'application/json' }),
40+
body: JSON.stringify(data),
41+
timeout: this.timeout,
42+
});
43+
44+
if (!response.ok) {
45+
throw new Error(await response.text());
46+
}
3447

35-
return response.data;
48+
return await response.json();
3649
} catch (e) {
3750
return handleError(e);
3851
}

0 commit comments

Comments
 (0)