Consider using request
IEvangelist opened this issue · 0 comments
IEvangelist commented
const endpoint = 'https://api.cognitive.microsofttranslator.com';
const key = 'c57xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxac3';
const region = 'canadacentral';
function translateText() {
let options = {
method: 'POST',
baseUrl: endpoint,
url: 'translate',
qs: {
'api-version': '3.0',
'to': ['de', 'it']
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Ocp-Apim-Subscription-Region': region,
'Content-type': 'application/json'
},
body: [{
'text': 'Hello World!'
}],
json: true,
};
request(options, function(err, res, body){
console.log(JSON.stringify(body, null, 4));
});
};
// Call the function to translate text.
translateText();