Last active
November 7, 2017 16:30
-
-
Save maxkatz/4ddf7dc6b3dddfd962cf5e72dfc1c597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// API URL | |
var url = "https://gateway.watsonplatform.net/language-translator/api/v2/translate"; | |
// Optional parameters | |
var text = request.get("text") || "Hello"; | |
var source = request.get("source") || "en"; | |
var target = request.get("target") || "es"; | |
// Credentials | |
var username = "Username from service credentials"; | |
var password = "Password from service credentials"; | |
// HTTP POST request | |
var XHRResponse = XHR2.send("POST", url, { | |
"headers": { | |
Authorization: "Basic " + encodeBase64(username + ":" + password), | |
"Content-Type": "application/json", | |
"Content-Accept": "application/json" | |
}, | |
"body": { | |
"text": text, | |
"source": source, | |
"target": target | |
} | |
}); | |
// Setting service response | |
Apperyio.response.success(XHRResponse.body, "application/json"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment