← Back to Use Cases
COLLABORATION & SHARING

API Mockups

Store fixture responses per endpoint/version; frontends hit read-only URLs while backends are in progress.

The Problem

Your frontend team is ready to build, but the backend API isn't done yet. You need realistic mock responses for different endpoints and versions so development can proceed in parallel.

Setting up a mock server is overkill, and hardcoding responses in the frontend makes them hard to update and share across the team.

The WrenDB Solution

Store mock API responses in a WrenDB stash with endpoint names as keys. Frontends fetch from public read URLs. Backend devs update fixtures with the master token. Simple, shareable, and version-controlled.

Step-by-Step Guide

1

Set up API mock stash

Create a stash for your API fixtures:

Terminal
# Create mock API stash
curl -X POST https://wrendb.com/api/stash

{
  "stash_id": "mocks456...",
  "master_token": "token-api789...",
  "message": "Save this token securely..."
}

# Add mock responses for different endpoints
curl -X POST https://wrendb.com/api/item/mocks456.../users-list \
  -d '[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]'

curl -X POST https://wrendb.com/api/item/mocks456.../user-profile \
  -d '{"id":1,"name":"Alice","email":"alice@example.com","role":"admin"}'

curl -X POST https://wrendb.com/api/item/mocks456.../products-v2 \
  -d '{"products":[{"id":101,"name":"Widget","price":29.99}],"version":"2.0"}'
2

Frontend uses mocks (no auth)

Create a simple API client that fetches from WrenDB:

api-client.js
const MOCK_STASH_ID = 'mocks456...';
const USE_MOCKS = true; // Toggle for dev vs production

async function fetchAPI(endpoint) {
  if (USE_MOCKS) {
    // Fetch from WrenDB - no auth needed
    const response = await fetch(
      `https://wrendb.com/api/item/${MOCK_STASH_ID}/${endpoint}`
    );
    return await response.json();
  } else {
    // Real API call
    const response = await fetch(`https://api.yourapp.com/${endpoint}`);
    return await response.json();
  }
}

// Usage in your app
async function loadUsers() {
  const users = await fetchAPI('users-list');
  console.log(users); // [{"id":1,"name":"Alice"},...]
}

async function loadUserProfile(userId) {
  const profile = await fetchAPI('user-profile');
  console.log(profile); // {"id":1,"name":"Alice",...}
}
3

Update mocks as API evolves

Backend team updates fixtures as the API design changes:

update-mocks.sh
#!/bin/bash

STASH_ID="mocks456..."
TOKEN="$MOCK_API_TOKEN"

# Update user profile with new fields
curl -X PUT "https://wrendb.com/api/item/$STASH_ID/user-profile" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "id": 1,
    "name": "Alice",
    "email": "alice@example.com",
    "role": "admin",
    "avatar_url": "https://example.com/avatar.jpg",
    "created_at": "2025-01-15T10:00:00Z"
  }'

echo "✅ Mock updated - frontend will get new fields immediately"

Advanced: API Versioning

Store different versions of the same endpoint:

Terminal
# v1 endpoint
curl -X POST https://wrendb.com/api/item/mocks456.../products-v1 \
  -d '[{"id":101,"name":"Widget","price":29.99}]'

# v2 endpoint with enhanced response
curl -X POST https://wrendb.com/api/item/mocks456.../products-v2 \
  -d '{
    "products": [
      {"id":101,"name":"Widget","price":29.99,"stock":45,"category":"tools"}
    ],
    "version": "2.0",
    "total_count": 1
  }'

Why This Works

  • Parallel development - Frontend and backend teams work independently
  • Instant updates - Change mock responses without restarting apps
  • Team-wide sharing - Everyone uses the same mock data
  • Easy transition - Just toggle a flag to switch to real API

Related Use Cases

Config Sharing - Share environment configs across teams CI/CD Breadcrumbs - Track build status publicly