Communicating with an External API
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// Executes when a player enters
App.onJoinPlayer.Add(function (player) {
App.httpGet(
"https://nickname.hwanmoo.kr/?format=json&count=1&max_length=6&whitespace=_",
null,
function (res) {
// Change the response to a JSON object
let response = JSON.parse(res);
player.name = response.words[0];
player.sendUpdated();
}
);
});// Activates function when q is pressed
App.addOnKeyDown(81, function (player) {
App.httpPost(
"https://postman-echo.com/post",
{
"test-header": "zep",
},
{
name: "zepscript",
},
(res) => {
let response = JSON.parse(res);
App.sayToAll(`header sent: ${response.headers["test-header"]}`, 0xffffff);
App.sayToAll(`data sent: ${response.form.name}`, 0xffffff);
}
);
});