# Cloud Code API 호출

> Invoke module endpoints using HTTP requests to the Cloud Code REST API.

모듈 엔드포인트를 실행하려면 Cloud Code API를 호출합니다. 자세한 내용은 [Cloud Code API 기술 자료](https://services.docs.unity.com/cloud-code/v1/index.html#tag/cloud-code/operation/runmodule)를 참고하십시오.

> **Note:**
>
> **참고:** 지난 15분 내에 모듈에 어떤 트래픽도 수신되지 않으면 콜드 스타트 지연을 경험하게 될 수 있습니다. 모듈에 대한 후속 호출이 발생하면 이는 더 빠르게 처리됩니다.

## Authentication##authentication

서비스 계정이나 상태 비보존 토큰을 사용하여 플레이어 또는 신뢰할 수 있는 클라이언트로 인증하려면 [인증](../authentication)을 참고하십시오. 받은 토큰을 요청 헤더에서 HTTP 인증을 위한 bearer 토큰으로 사용합니다.

```bash
Authorization: Bearer <BEARER_TOKEN>
```

## 모듈 엔드포인트 요청 실행##run-module-endpoint-request

POST 요청을 다음으로 보내 Cloud Code API를 호출합니다.

```http request
https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/<MODULE_NAME>/<FUNCTION_NAME>
```

다음과 같이 경로 파라미터를 정의합니다.

* `PROJECT_ID` - 프로젝트 ID입니다.
* `MODULE_NAME` - 모듈 이름입니다.
* `FUNCTION_NAME` - 모듈 엔드포인트 이름으로, 코드에서 정의한 `CloudCodeFunction`입니다.

간단한 cURL 커맨드는 다음과 같습니다.

```bash
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/<MODULE_NAME>/<FUNCTION_NAME>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <BEARER_TOKEN>'
```

## 요청 페이로드##request-payload

메서드 서명 내의 모듈 함수에서 파라미터를 정의할 수 있습니다. 모듈 함수의 구조를 만드는 방법은 [모듈 구조](../module-structure)를 참고하십시오. 예를 들어 다음 메서드는 문자열 파라미터 weapon과 bodyPart를 정의합니다.

```csharp
[CloudCodeFunction("IntroduceGuard")]
public string IntroduceGuard(string weapon, string bodyPart)
{
return $"I used to be an adventurer like you. Then I took an ${weapon} to the ${bodyPart}.";
}
```

이 파라미터는 엔드포인트를 호출할 때 요청 본문에서 JSON으로 전달됩니다. 파라미터의 대소문자는 메서드 서명과 일치해야 합니다.

```json
{
  "params": {
    "weapon": "arrow",
    "bodyPart": "knee"
  }
}
```

완전한 cURL 커맨드는 다음과 같습니다.

```bash
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/<MODULE_NAME>/<FUNCTION_NAME>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <BEARER_TOKEN>' \
--data-raw '{
  "params": {
    "weapon": "arrow",
    "bodyPart": "knee"
  }
}'
```

## 샘플 출력##sample-output

다음은 모듈 출력 예시입니다.

```json
{
    "output": "I used to be an adventurer like you. Then I took an arrow to the knee."
}
```
