TypeScript client
The TypeScript client for Windmill allows you to interact with the Windmill platform using TypeScript in Bun / Deno runtime. This client provides a set of functions and utilities to access Windmill resources and perform various operations.
The TypeScript Windmill SDK can be found at https://app.windmill.dev/tsdocs/modules.html
Installation
Within Windmill, the client is available out of the box: import windmill-client in a Bun script or npm:windmill-client in a Deno script. For local development, install Bun or Deno and the client is fetched from the npm registry.
- TypeScript (Bun)
- TypeScript (Deno)
import * as wmill from 'windmill-client';
import * as wmill from 'npm:windmill-client';
Usage
The TypeScript client provides several functions that you can use to interact with the Windmill platform. Here's an example of how to use the client to get a resource from Windmill:
- TypeScript (Bun)
- TypeScript (Deno)
import * as wmill from 'windmill-client';
export async function main() {
let x = await wmill.getResource('u/user/name');
}
import * as wmill from 'npm:windmill-client';
export async function main() {
let x = await wmill.getResource('u/user/name');
}
In the example above, the getResource function is used to retrieve a resource with the path 'u/user/name' from the Windmill platform. The returned resource can be further processed or used as needed in your application.
Cancel a job
cancelJob(jobId, reason?) cancels a queued or running job and returns the message from the cancel endpoint. It is the TypeScript equivalent of the Python client's cancel_job.
- TypeScript (Bun)
- TypeScript (Deno)
import * as wmill from 'windmill-client';
export async function main() {
const jobId = await wmill.runScriptByPathAsync('f/scripts/long_task', { input: 'value' });
// Later on, stop the job while it is still queued or running
await wmill.cancelJob(jobId, 'superseded by a newer run');
}
import * as wmill from 'npm:windmill-client';
export async function main() {
const jobId = await wmill.runScriptByPathAsync('f/scripts/long_task', { input: 'value' });
// Later on, stop the job while it is still queued or running
await wmill.cancelJob(jobId, 'superseded by a newer run');
}
jobId is the UUID of the job to cancel. reason is optional and is stored as the job's cancel reason, visible in the runs menu; it defaults to cancelled via cancelJob method when omitted.