npm package · v1.0.0

Your API routes,
auto-synced to APIYatra

Install the apiyatra package in your Node.js project. Every route you define automatically appears as a ready-to-test request in your APIYatra workspace — no manual copy-paste, ever.

$npm install apiyatra

How it works

4 steps from install to testing

01

Install the package

Add apiyatra to your Node.js project with a single command.

bash
npm install apiyatra
02

Get your workspace credentials

Open APIYatra → Workspace Settings → copy your Secret ID and Secret Code.

bash
# From APIYatra Workspace Settings
Secret ID:   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Secret Code: your-secret-code
03

Call syncYatra in your app

Pass your existing Express routes array — the same one you already use to mount routes.

typescript
import { syncYatra } from 'apiyatra';
import authRouter from './modules/auth/auth.routes';
import usersRouter from './modules/users/users.routes';

await syncYatra({
  secretId:       'your-workspace-secret-id',
  secretCode:     'your-workspace-secret-code',
  collectionName: 'My App APIs',
  expressRoutes: [
    { path: '/api/v1/auth',  route: authRouter  },
    { path: '/api/v1/users', route: usersRouter },
  ],
});
04

Open APIYatra — done

Your collection appears instantly with all routes organized into folders, ready to test.

bash
✓ Collection 'My App APIs' synced
  📁 Auth
     POST    /api/v1/auth/register
     POST    /api/v1/auth/login
     POST    /api/v1/auth/refresh
  📁 Users
     GET     /api/v1/users
     GET     /api/v1/users/:id
     PATCH   /api/v1/users/:id
     DELETE  /api/v1/users/:id

Multiple integration styles

Works with any Node.js backend setup

Express.js (Auto)

Recommended

Pass your Express Router directly — package auto-extracts every route, method, and path.

import express from 'express';
import { syncYatra } from 'apiyatra';
import * as authValidators from './modules/auth/auth.validator';

const authRouter = express.Router();
authRouter.post('/register', ...);
authRouter.post('/login', ...);
authRouter.post('/refresh', ...);

// One call — all routes synced automatically
await syncYatra({
  secretId:       process.env.APIYATRA_SECRET_ID,
  secretCode:     process.env.APIYATRA_SECRET_CODE,
  collectionName: 'My Backend APIs',
  expressRoutes: [
    {
      path: '/api/v1/auth',
      route: authRouter,
      // Optional: pass Zod/Joi/Yup validators
      // Package auto-generates request body samples
      validators: authValidators,
    },
  ],
});

Manual Routes

Define routes manually with full control over names, groups, headers and body examples.

import { syncRoutes } from 'apiyatra';

await syncRoutes({
  secretId:       process.env.APIYATRA_SECRET_ID,
  secretCode:     process.env.APIYATRA_SECRET_CODE,
  backendUrl:     'https://api.apiyatra.com',
  collectionName: 'Payment APIs',
  baseUrl:        'https://api.myapp.com',
  routes: [
    {
      method: 'POST',
      path:   '/api/payments/charge',
      name:   'Charge Card',
      group:  'Payments',
      body: {
        amount:   100,
        currency: 'USD',
        cardToken: 'tok_visa',
      },
    },
    {
      method: 'GET',
      path:   '/api/payments/:id',
      name:   'Get Payment',
      group:  'Payments',
    },
  ],
});

OpenAPI / Swagger

Already have an OpenAPI spec? Use the CLI to sync it directly — no code changes needed.

# 1. Create config file in your project root
# .apiyatra.json
{
  "secretId":       "your-workspace-secret-id",
  "secretCode":     "your-workspace-secret-code",
  "backendUrl":     "https://api.apiyatra.com",
  "specFile":       "./openapi.yaml",
  "collectionName": "My API"
}

# 2. Run the CLI
npx apiyatra sync

# Or add to package.json scripts:
# "sync:api": "apiyatra sync"

With Validators

Smart

Pass your Zod, Joi or Yup validators — package auto-generates realistic request body samples.

import { z } from 'zod';
import { syncYatra } from 'apiyatra';

// Your existing validators
export const createUserSchema = z.object({
  name:     z.string(),
  email:    z.string().email(),
  password: z.string().min(8),
  role:     z.enum(['admin', 'user']),
});

// Pass validators — body samples auto-generated:
// { name: "Sample Name", email: "user@example.com",
//   password: "password123", role: "admin" }
await syncYatra({
  secretId:       '...',
  secretCode:     '...',
  collectionName: 'User APIs',
  expressRoutes: [
    {
      path:       '/api/v1/users',
      route:      usersRouter,
      validators: { createUserSchema }, // ← just pass exports
    },
  ],
});
Zero config
Pass your router — package does the rest. No annotations, no decorators.
🧠
Smart body samples
Zod, Joi and Yup validators auto-generate realistic request body examples.
📁
Auto folders
Routes grouped into folders by path prefix automatically.
🔄
Re-run anytime
Run on every deploy to keep your collection in sync with your codebase.
🌐
OpenAPI support
Already have a spec file? CLI syncs it directly — no code changes.
🔒
Secure
Credentials stay in your env vars. Nothing sensitive sent to third parties.

Ready to sync your APIs?

Create a free APIYatra account, grab your workspace credentials, and have your first collection synced in under 2 minutes.

Quick reference
FunctionUse when
syncYatra()You have an Express.js app — auto-extracts all routes
syncRoutes()You want manual control over route names, groups, body examples
apiyatra sync (CLI)You have an OpenAPI / Swagger spec file
💡
Store credentials in env vars
# .env
APIYATRA_SECRET_ID=your-workspace-secret-id
APIYATRA_SECRET_CODE=your-workspace-secret-code