Web
You can use the following .npmrc to install the dependencies from the buf.build registry.
toml
@buf:registry=https://buf.build/gen/npm/v1/or using pnpm:
bash
pnpm config set @buf:registry https://buf.build/gen/npm/v1/To install dependencies:
bash
pnpm add @buf/minekube_gate.connectrpc_es@latestbash
bun add @buf/minekube_gate.connectrpc_es@latestbash
npm install @buf/minekube_gate.connectrpc_es@latestbash
yarn add @buf/minekube_gate.connectrpc_es@latestRefer to the ConnectRPC documentation for more information on how to use ConnectRPC with TypeScript on browser side.
Browser support
To use the Gate API in the browser, check out the Web documentation.
ts
import { createClient } from '@connectrpc/connect';
import { createConnectTransport } from '@connectrpc/connect-web';
import { GateService } from '@buf/minekube_gate.connectrpc_es/minekube/gate/v1/gate_service_connect.js';
const transport = createConnectTransport({
baseUrl: 'http://localhost:8080',
});
async function main() {
const client = createClient(GateService, transport);
const res = await client.listServers({});
console.log(JSON.stringify(res.servers, null, 2));
}
void main();WARNING
Note that we had to append .js to the import path in line 3 due Node.js requiring .js for CommonJS modules, other than in Bun.
ts
import { GateService } from '@buf/minekube_gate.connectrpc_es/minekube/gate/v1/gate_service_connect.js';Sample project
This sample project is located in the docs/developers/api/typescript/node directory.
To install dependencies:
bash
pnpm installTo run:
bash
node --experimental-strip-types index.ts
[
{
"name": "server1",
"address": "localhost:25566",
"players": 0
},
{
"name": "server2",
"address": "localhost:25567",
"players": 0
},
{
"name": "server3",
"address": "localhost:25568",
"players": 0
},
{
"name": "server4",
"address": "localhost:25569",
"players": 0
}
]This project was created using pnpm init in pnpm v9.5.0. pnpm is a fast, disk space efficient package manager.
