# Call to Cloud Code API

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

Call out to the Cloud Code API to run your module endpoints. Refer to [Cloud Code API documentation](https://services.docs.unity.com/cloud-code/v1/index.html#tag/cloud-code/operation/runmodule) for more information.

> **Note:**
>
> If a module hasn't received any traffic in the last 15 minutes, you might experience a cold start latency. Any subsequent calls to the module are faster.

## Authentication

Refer to [Authentication](../authentication) to authenticate as a player or a trusted client using a service-account or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header:

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

## Run module endpoint request

Call out to the Cloud Code API by sending a POST request to the following URL:

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

Define the following path parameters:

* `PROJECT_ID`: The ID of the project.
* `MODULE_NAME`: The name of the module.
* `FUNCTION_NAME`: The name of the module endpoint. This is the `CloudCodeFunction` you defined in your code.

The following is an example of a simple Curl command:

```bash title="A simple Curl command"
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

You can define parameters in your module function inside the method signature.  Refer to [module structure](../module-structure) on how to structure your module functions.
For example, the following method defines the string parameters `weapon` and `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}.";
}
```

The request body passes these parameters as JSON when you call the endpoint. The casing of the parameter must match the method signature.

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

The following is an example of a complete Curl command:

```bash title="A complete Curl command"
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

The following shows the example output of a module.

```json title="An example output of a module"
{
    "output": "I used to be an adventurer like you. Then I took an arrow to the knee."
}
```
