01
/Request for a JWT.
/**
* Demo program for requesting a JWT from the Rozetta API.
*/
const fetch = require('node-fetch');
const URL = 'https://translate.rozetta-api.io/api/v1/token';
const data = {
accessKey: 'my-access-key',
secretKey: 'my-secret-key',
duration: 300
};
const getJWT = async () => {
const response = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
const responseJSON = await response.json();
console.log(`JWT: ${responseJSON.data.encodedJWT}`);
};
getJWT();
02
/Send API request with JWT.
/**
* Demo prorgram of authentication by JWT.
*/
const fetch = require('node-fetch');
const token = 'my-jwt';
const sampleRequest = async () => {
const url = 'https://translate.rozetta-api.io/api/v1/hello';
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`
}
});
const responseJSON = await response.json();
console.log(responseJSON);
};
sampleRequest();