Testing Hiro RPCs via API Client #
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 #
- Install Bruno
- Install Nakama and Hiro and have them running
- Download Hiro’s OpenAPI Collection
Importing the OpenAPI Collection #
Import the OpenAPI Collection in Bruno by following these steps:
- Navigate to Import Collection -> OpenAPI V3 Spec
- Select the hiroOpenAPI.yml file
- Choose a location to save the collection
- 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"
.
Creating a Bearer Token #
We can create a new user via the Command Line to receive a Bearer Token
:
|
|
The response should look like this:
|
|
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:
- Click the … menu on the Hiro RPC API Collection
- Select Settings -> Auth
- 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.
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: