Testing Hiro RPCs via API Client #

This guide was written using the Bruno API Client, but any other API Client can be used as long as it supports importing collections with OpenAPI format.

When testing your Hiro RPC functions, using an API Client can be a good alternative to using the game client, enabling a faster and more efficient way to test your functions.

You can find the collection of RPCs that have been registered by Hiro from your Nakama Console in the Runtime Modules -> Registered RPC Functions page. These RPCs are open to be called via the API Client.

Prerequisites #

Importing the OpenAPI Collection #

Import the OpenAPI Collection in Bruno by following these steps:

  1. Navigate to Import Collection -> OpenAPI V3 Spec
  2. Select the hiroOpenAPI.yml file
  3. Choose a location to save the collection
  4. Click Import

Setting Authentication #

All the requests need to have a Bearer Token, otherwise the server will return an error saying "Auth token or HTTP key required".

Every time the token expires, all the steps in this subsection need to be redone.

Creating a Bearer Token #

We can create a new user via the Command Line to receive a Bearer Token:

1
2
3
4
curl --location 'http://127.0.0.1:7350/v2/account/authenticate/custom?create=true&username=<username>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ZGVmYXVsdGtleTo=' \
--data '{"id":"uniqueidentifier"}'

The response should look like this:

1
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI2OTE3MTI0MS1jZmY1LTQ2ZjAtOTU1MC04MmQ5Yzc3YjFkNmQiLCJ1aWQiOiJmYjVjNTRiNy0xMmU5LTQyM2YtOWE0OC04YTBlMjNmNTM3YmMiLCJ1c24iOiJQbGF5ZXI1NzgwMTQwNyIsImV4cCI6MTcyMTI5NDczOX0.lSOoEB0vmESYWsfKhnOrn8EapOK7OdCT-ZM2otqvYwA","refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI2OTE3MTI0MS1jZmY1LTQ2ZjAtOTU1MC04MmQ5Yzc3YjFkNmQiLCJ1aWQiOiJmYjVjNTRiNy0xMmU5LTQyM2YtOWE0OC04YTBlMjNmNTM3YmMiLCJ1c24iOiJQbGF5ZXI1NzgwMTQwNyIsImV4cCI6MTcyMTgxMzEzOX0.1o9q9O4eXMU0eL0DahAQ_3Q1q_lRsJfSrw-1icoT_Xk"}

The first argument (token) is the Bearer Token that we want. We do not need the refresh_token for purposes of this guide.

Setting the Bearer Token #

Now in Bruno, set the Bearer Token as a global setting:

  1. Click the menu on the Hiro RPC API Collection
  2. Select Settings -> Auth
  3. Click No Auth and select Bearer Token -> Set the token field

When making a request, set the Auth mode to Inherit by going to the Auth tab, clicking No Auth and selecting Inherit.

Bruno after making a Post request on a Hiro RPC Function
Bruno after making a Post request on a Hiro RPC Function

Testing an RPC Call #

To make an RPC call, select the POST request related to the RPC call that you want to test. In this case we will test RPC_ID_ECONOMY_STORE_GET.

Next set the body of the request by going to the Body tab and setting the storeType field. In this case we set it to ECONOMY_STORE_TYPE_GOOGLE_PLAY.

After making the request, Bruno should look like this:

Bruno after making a Post request on a Hiro RPC Function
Bruno after making a Post request on a Hiro RPC Function