Aquila

Typed clients

Generate a Go, TypeScript or C# client for the Aquila API from its protobuf schema.

The fleets, allocation and matchmaking APIs are defined in protobuf. Their schema is published as a buf module at:

https://studio-docs.aquilahosting.com/aquila-api.tar.gz

Generate a client from it with buf. The plugins below run on buf's servers, so buf is the only thing to install. WatchTicket streams only work through a generated client.

Go

buf.gen.yaml:

version: v2
inputs:
  - tarball: https://studio-docs.aquilahosting.com/aquila-api.tar.gz
managed:
  enabled: true
  override:
    # Your own module path, where the generated packages will live.
    - file_option: go_package_prefix
      value: example.com/mygame/gen/aquila
  disable:
    - module: buf.build/bufbuild/protovalidate
    - module: buf.build/googleapis/googleapis
plugins:
  - remote: buf.build/protocolbuffers/go:v1.36.12
    out: gen/aquila
    opt: paths=source_relative
  - remote: buf.build/connectrpc/go:v2.0.2
    out: gen/aquila
    opt: paths=source_relative
buf generate
go mod tidy
package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"os"

	"connectrpc.com/connect/v2"
	"connectrpc.com/connect/v2/connecthttp"

	fleetsv1 "example.com/mygame/gen/aquila/api/fleets/v1"
	"example.com/mygame/gen/aquila/api/fleets/v1/fleetsv1connect"
)

func main() {
	key := os.Getenv("AQUILA_API_KEY")
	auth := func(next connect.ClientFunc) connect.ClientFunc {
		return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) {
			if call, ok := connect.CallInfoForClientContext(ctx); ok {
				call.RequestHeader().Set("Authorization", "Bearer "+key)
			}
			return next(ctx, spec)
		}
	}
	client := connect.NewClient(
		connecthttp.NewTransport(http.DefaultClient, "https://api.aquilahosting.com"),
		auth,
	)
	fleets := fleetsv1connect.NewFleetServiceClient(client)

	res, err := fleets.ListFleets(context.Background(), &fleetsv1.ListFleetsRequest{
		OrganizationId: os.Getenv("ORG_ID"),
	})
	if err != nil {
		log.Fatal(err)
	}
	for _, f := range res.Fleets {
		fmt.Println(f.Name, f.Zone, f.Replicas)
	}
}

For allocation, make a second client with the zone's base URL, https://allocate-eu.aquilahosting.com, and allocationv1connect.NewAllocationServiceClient.

TypeScript

buf.gen.yaml:

version: v2
inputs:
  - tarball: https://studio-docs.aquilahosting.com/aquila-api.tar.gz
plugins:
  - remote: buf.build/bufbuild/es:v2.16.0
    out: src/gen
    include_imports: true
    opt:
      - target=ts
      - import_extension=js
buf generate
npm install @bufbuild/protobuf @connectrpc/connect @connectrpc/connect-node
import { createClient, type Interceptor } from "@connectrpc/connect"
import { createConnectTransport } from "@connectrpc/connect-node"
import {
  MatchmakingService,
  TicketState,
} from "./gen/api/matchmaking/v1/matchmaking_pb.js"

const auth: Interceptor = (next) => (req) => {
  req.header.set("Authorization", `Bearer ${process.env.AQUILA_API_KEY}`)
  return next(req)
}

const matchmaking = createClient(
  MatchmakingService,
  createConnectTransport({
    baseUrl: "https://api.aquilahosting.com",
    httpVersion: "1.1",
    interceptors: [auth],
  })
)

const organizationId = process.env.ORG_ID!
const { ticket } = await matchmaking.createTicket({
  organizationId,
  queue: "duel",
  playerIds: ["alice"],
})

// Ends once the ticket is assigned, expired or cancelled.
for await (const { ticket: t } of matchmaking.watchTicket({
  ticket: { organizationId, ticketId: ticket!.ticketId },
})) {
  console.log(TicketState[t!.state], t!.assignment?.address)
}

Keep this in your game backend. The key must never reach a game client.

C#

buf.gen.yaml:

version: v2
inputs:
  - tarball: https://studio-docs.aquilahosting.com/aquila-api.tar.gz
managed:
  enabled: true
  override:
    - file_option: csharp_namespace_prefix
      value: Aquila
  disable:
    - module: buf.build/bufbuild/protovalidate
    - module: buf.build/googleapis/googleapis
plugins:
  - remote: buf.build/protocolbuffers/csharp:v33.2
    out: Gen
    include_imports: true
    opt: base_namespace=
  - remote: buf.build/grpc/csharp:v1.76.0
    out: Gen
    opt: base_namespace=
buf generate
dotnet add package Google.Protobuf
dotnet add package Grpc.Net.Client
dotnet add package Grpc.Net.Client.Web

The client speaks gRPC-Web over HTTP/1.1, which the API and every zone's allocation endpoint accept.

using Aquila.Matchmaking.V1;
using Grpc.Core;
using Grpc.Core.Interceptors;
using Grpc.Net.Client;
using Grpc.Net.Client.Web;

var key = Environment.GetEnvironmentVariable("AQUILA_API_KEY");
var organizationId = Environment.GetEnvironmentVariable("ORG_ID");

using var channel = GrpcChannel.ForAddress("https://api.aquilahosting.com", new GrpcChannelOptions
{
    HttpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()),
    HttpVersion = new Version(1, 1),
    HttpVersionPolicy = HttpVersionPolicy.RequestVersionExact,
});
var invoker = channel.Intercept(metadata =>
{
    metadata.Add("Authorization", $"Bearer {key}");
    return metadata;
});
var matchmaking = new MatchmakingService.MatchmakingServiceClient(invoker);

var created = await matchmaking.CreateTicketAsync(new CreateTicketRequest
{
    OrganizationId = organizationId,
    Queue = "duel",
    PlayerIds = { "alice" },
});

// Ends once the ticket is assigned, expired or cancelled.
using var watch = matchmaking.WatchTicket(new WatchTicketRequest
{
    Ticket = new TicketRef { OrganizationId = organizationId, TicketId = created.Ticket.TicketId },
});
await foreach (var update in watch.ResponseStream.ReadAllAsync())
{
    Console.WriteLine($"{update.Ticket.State} {update.Ticket.Assignment?.Address}");
}

This is for a .NET game backend. Unity or Unreal servers report their state in one of the ways under Running a game. The API key must never ship in a game server or client.

Other languages

Any language with an HTTP client can call the APIs with JSON, as the quickstart does with curl. The API reference lists every request and response.

Code generators for other languages read the same module. buf's plugin registry has protobuf plugins for C++, Java, Python and more.

On this page