Call from Unity game server (Multiplay Hosting)
You can call a module endpoint from a dedicated game server using Multiplay Hosting.
Note: If a module has not received any traffic in the last 15 minutes, you may experience a cold start latency. Any subsequent calls to the module are faster.
Prerequisites
- The game server you are invoking Cloud Code from and any related resources must exist in the same Unity Cloud Dashboard project and environment.
- Onboard with Multiplay Hosting.
Call out to Cloud Code
Follow the steps below to call out to a Cloud Code module endpoint from a game server.
Authentication
You can authenticate requests using a Multiplay Hosting token or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header.
Authenticating with a Multiplay token is recommended. Authenticating with a stateless tokens requires you to create a service account and store the private key securely, whereas Multiplay tokens do not require this and are less complex to manage.
Authenticate using a Multiplay Hosting token
See the Game Server Documentation here.
Authenticate using a stateless token
To use a stateless token, you need to create a service account and call the Token Exchange API. Refer to authenticating trusted clients for the Cloud Code Client API.
Call a module endpoint
You can call a module endpoint using any HTTP library that is native to the codebase. Use the retrieved authentication token as a bearer token for HTTP authentication in the request header. An example CURL request to call an endpoint using the Cloud Code API could look like this:
curl -X POST -H "Authorization: Bearer <BEARER_TOKEN>" 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/<MODULE_NAME>/<FUNCTION_NAME>'