Attaching Tokens to HTTP Requests Using JavaScript
When interacting with Trongate API endpoints, it's essential to include the Trongate token in the HTTP request headers for authentication. Below are demonstrations on how to attach a Trongate token to HTTP requests, using JavaScript.
Using XMLHttpRequest
const targetUrl = 'your_base_url/trongate_tokens/id';
const token = 'your_trongate_token'; // Replace with your actual Trongate token
const http = new XMLHttpRequest();
http.open('GET', targetUrl);
http.setRequestHeader('Content-type', 'application/json');
http.setRequestHeader('trongateToken', token);
http.send();
http.onload = function() {
console.log(http.status);
console.log(http.responseText);
};
Using Fetch API
const targetUrl = 'your_base_url/trongate_tokens/id';
const token = 'your_trongate_token'; // Replace with your actual Trongate token
fetch(targetUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'trongateToken': token
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));