🛰️외부 API 통신하기

외부 API에 GET, POST 등의 요청을 인자와 함께 보낼 수 있습니다.

httpGet

한국어 별명 생성기 API를 이용해 입장하는 플레이어의 닉네임을 바꿔보기

// 플레이어가 입장할 때 동작하는 함수
App.onJoinPlayer.Add(function (player) {
	App.httpGet(
		"https://nickname.hwanmoo.kr/?format=json&count=1&max_length=6&whitespace=_",
		null,
		function (res) {
			// 응답 결과를 JSON 오브젝트로 변경
			let response = JSON.parse(res);
			player.name = response.words[0];
			player.sendUpdated();
		}
	);
});

httpPost

앱에서 보낸 헤더와 데이터를 응답으로 받아 채팅창에 출력해보기.

Last updated

Was this helpful?