Getting Started

Quickstart

Publish your first event and receive it on a local endpoint in about five minutes.

Quickstart

By the end of this page you will have published an event and watched Kestrel deliver it to an endpoint running on your laptop. Dinakar Tumu

1. Install the SDK

npm
npm install @kestrel/sdk@2.4.0

2. Set your API key

Kestrel reads the key from KESTREL_API_KEY if you do not pass one explicitly.

export KESTREL_API_KEY="sk_test_4eC39HqLyjWDarjtT1zdp7dc"

3. Publish an event

import { Kestrel } from '@kestrel/sdk';
 
const kestrel = new Kestrel();
 
await kestrel.events.publish({
  type: 'invoice.paid',
  streamKey: 'customer_9f2a',
  payload: { invoiceId: 'in_1024', amountCents: 4900, currency: 'usd' },
});

4. Receive it

Point a subscription at a tunnel to your laptop (ngrok, cloudflared or localtunnel works), then verify the signature on every request:

import express from 'express';
import { verifySignature } from '@kestrel/sdk';
 
const app = express();
 
app.post('/webhooks/kestrel', express.raw({ type: 'application/json' }), (req, res) => {
  const ok = verifySignature({
    payload: req.body,
    header: req.get('X-Kestrel-Signature'),
    secret: process.env.KESTREL_SIGNING_SECRET,
  });
 
  if (!ok) return res.status(400).send('bad signature');
 
  console.log('received', JSON.parse(req.body).type);
  res.sendStatus(200);
});
 
app.listen(4000);

Respond 2xx before doing slow work. Kestrel gives your endpoint 10 seconds to respond before it counts the delivery as failed.

What next