Query data to display on website

Hello all,

Is there a recommended way to query data to be displayed on a website?

I’m looking for:

  • Leaderboards
  • Tournaments
  • List of matches in progress (hopefully with user count)
  • Logged in users count (active sessions)
  • Registered users count
  • list of public groups/clans

Can all of these be done from Server to Server calls? Or do they require a userId in the context?

Is there a “best practices” way to query this data as a payload to be displayed on a website/dashboard?

Many thanks in advance for your reply.

Hello @Antviss,

It would help to know what you’re trying to accomplish. If this is for a custom dashboard, you can achieve most of what you want setting up RPCs and using S2S calls as advised here. However, doing some of these operations frequently won’t scale.

I’ve inlined the answer for each point or linked the relevant docs page.

Nakama: Function Reference | Heroic Labs Documentation

Nakama: Function Reference | Heroic Labs Documentation

  • List of matches in progress (hopefully with user count)

You’d have to use the match listing API Nakama: Match Listing | Heroic Labs Documentation, as for the user count, you’d have to appropriately use the labels to keep track of that yourself.

  • Logged in users count (active sessions)

The right way of keeping track of this would be using Prometheus, as we expose the count of current active sessions.

  • Registered users count

We purposefully don’t provide an API for this, as it’s an operation that won’t scale. You could use a custom db query, but we strongly discourage it because of the above.

You can get an estimate on the Nakama dashboard: Nakama: Accounts | Heroic Labs Documentation.

Thank you so much for the reply @sesposito It definitely helps.

To answer your initial question, it’s not quite a dashboard per se, but instead showing some live game data on our website to show users. I will have an Express JS internal server which caches most of the data from Nakama and the public website will get data from it in the backend instead of the Nakama server directly.

Am I right in my understanding that S2S RPC calls do not allow a userID (context) to be sent?

If that’s correct, do all these Runtime Functions work without a user context? If not, is it ok to use the 0000 default user inside the function to get the data?

As for the Match Listing API, does this include matches already in progress/which have started?

Thank you again!

The context is not sent explicitly by the clients, it is provided to the registered RPC functions when invoked. If the call comes from a client with a session token, the context will contain the userID, but if it’s a S2S call authenticated using the server http key, no userID will be populated in the context.

You can however set up the RPC calls to receive any payload you’d like to send in the requests.

The match listing API can be used to list all matches, to filter matches for a given state according to your game semantics, you have to update the label from within the match handlers and then use the query language Nakama: Query Syntax | Heroic Labs Documentation. Labels are only supported in authoritative matches.

Thank you for your thoroughness, @sesposito . It is much appreciated!