Skip to content

Commit

Permalink
migrate axios to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwi committed Jan 10, 2024
1 parent 3a86198 commit 40570f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 83 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The `reference` field (aka subscriber) will be used in the future for inbound ca



In the example application, we use `axios` to retrieve the token.
In the example application, we use `fetch` to retrieve the token.

## Instantiate the client and call the destination

Expand All @@ -53,4 +53,4 @@ const call = await client.dial({
await call.start()
```

For now, please run with debugging on to help with reporting issues.
For now, please run with debugging on to help with reporting issues.
23 changes: 15 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require('dotenv').config();
const express = require('express');
const session = require('express-session');
const app = express();
const axios = require('axios');
const base64url = require('base64url');
const crypto = require('crypto');

Expand Down Expand Up @@ -34,13 +33,21 @@ const host = process.env.RELAY_HOST
async function apiRequest(endpoint, payload = {}, method = 'POST') {
var url = `https://${process.env.SIGNALWIRE_SPACE}${endpoint}`

resp = await axios.post(url, payload, {
auth: {
username: process.env.SIGNALWIRE_PROJECT_KEY,
password: process.env.SIGNALWIRE_TOKEN
}
})
return resp.data
const response = await fetch(url, {
method: method,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + Buffer.from(process.env.SIGNALWIRE_PROJECT_KEY + ':' + process.env.SIGNALWIRE_TOKEN).toString('base64')
},
body: JSON.stringify(payload)
});

if (response.ok) {
return await response.json();
} else {
console.log(await response.text());
throw new Error(`HTTP error! status: ${response.status}`);
}
}

app.get('/', async (req, res) => {
Expand Down
72 changes: 0 additions & 72 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.5.0",
"base64url": "^3.0.1",
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
Expand Down

0 comments on commit 40570f1

Please sign in to comment.