# 외부 API 통신하기

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

### httpGet

[<mark style="color:purple;">한국어 별명 생성기</mark>](https://nickname.hwanmoo.kr/) API를 이용해 입장하는 플레이어의 닉네임을 바꿔보기

![](/files/0VxANpjdKHgP3PR0oaOX)

```jsx
// 플레이어가 입장할 때 동작하는 함수
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

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

```jsx
// q를 눌렀을 때 실행되는 함수
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(`보낸 헤더: ${response.headers["test-header"]}`, 0xffffff);
			App.sayToAll(`보낸 데이터: ${response.form.name}`, 0xffffff);
		}
	);
});
```

{% hint style="warning" %}
참고&#x20;

\- 튜토리얼의 App type은 미니게임(Mini game)을 권장합니다.&#x20;

\- .js파일의 파일이름은 반드시 main 이어야 합니다. main.js 파일을 준비합니다.&#x20;

\- 배포 방법을 아직 모르신다면, [<mark style="color:purple;">ZEP Script 배포 가이드</mark>](/creator/dev-guide/zep-script.md)를 참고해주세요.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-kr.zep.us/creator/reference/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
