Skip to content

Instantly share code, notes, and snippets.

@maxkatz
Last active November 7, 2017 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxkatz/4ddf7dc6b3dddfd962cf5e72dfc1c597 to your computer and use it in GitHub Desktop.
Save maxkatz/4ddf7dc6b3dddfd962cf5e72dfc1c597 to your computer and use it in GitHub Desktop.
// 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