Skip to content

Using a Client

Assuming you already have @tempojs/client as a dependency in your project, then all you need to do is import models from your shared codebase to use them:

import { GreeterClient } from '../shared';
// creates a new channel pointing at the Tempo server running locally
const channel = TempoChannel.forAddress('http://localhost:3000');
channel
.getClient(GreeterClient)
.sayHello({ name: 'World' })
.then((response) => {
console.log(response.serviceMessage);
})
.catch((e) => {
if (e instanceof TempoError) {
console.error(e);
}
});

or more simply if your project supports top-level await

const channel = TempoChannel.forAddress("http://localhost:3000");
const client = channel.getClient(GreeterClient);
const response = await client.sayHello({name: "World"});
console.log(response.serviceMessage);