Skip to main content

TypeScript SDK

The official TypeScript/JavaScript SDK for Mokra mock servers and MockWorld Tests.
The TypeScript SDK is coming soon. For now, you can use the HTTP API directly or the Ruby/Python SDKs.

Installation (Coming Soon)

npm install @mokra/sdk

Preview API

import { mockworld, configure } from '@mokra/sdk';

// Configure
configure({
  apiKey: process.env.MOKRA_API_KEY,
});

// Create a world
const world = mockworld({
  name: "My test",
  services: ["stripe", "shopify"]
});

// Run code
await world.run(async () => {
  // Your code here
  const stripe = new Stripe('sk_test_anything');
  await stripe.charges.create({ amount: 5000, currency: 'usd' });
});

// Observe
world.observe();

// Assert
world.assert("a charge was created");

Using fetch directly

Until the SDK is available, you can use fetch with the Mokra API:
// Make requests through Mokra proxy
const response = await fetch('https://api.mokra.ai/mock/stripe/v1/charges', {
  method: 'POST',
  headers: {
    'X-API-Key': process.env.MOKRA_API_KEY,
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: 'amount=5000&currency=usd'
});

const charge = await response.json();

HTTP API

See the HTTP API reference for direct API usage.

Next steps