← Back to Use Cases
LOCAL DEV & TESTING

API Mocking

Store mock responses for dev and testing. Update them without redeploying anything.

The Problem

You're developing against a third-party API that's slow, rate-limited, or costs money per request. You need mock responses for testing.

The WrenDB Solution

Store mock API responses in WrenDB. Update them anytime without touching code.

Complete Example

Example
# Store mock responses
curl -X POST https://wrendb.com/api/item/$STASH_ID/mock-user-api \
  -H "Content-Type: application/json" \
  -d '{
    "id": 123,
    "name": "John Doe",
    "email": "john@example.com"
  }'

# In your test code
import requests

def get_user(user_id, use_mock=True):
    if use_mock:
        response = requests.get(
            f'https://wrendb.com/api/item/{STASH_ID}/mock-user-api'
        )
        return response.json()
    else:
        # Real API call
        return requests.get(f'https://api.example.com/users/{user_id}').json()

# In your tests
def test_user_profile():
    user = get_user(123, use_mock=True)
    assert user['name'] == 'John Doe'
    assert user['email'] == 'john@example.com' 

Related Use Cases

Session Stash Config Sharing