DBindly Docs
Getting Started

Configuration

Configuration Options

Pass these options to DBindly.init():

DBindly.init({
  // Required
  apiUrl: 'https://dbindly.com/api',

  // Authentication
  apiKey: 'pk_live_your_api_key',

  // Caching
  cache: true,
  cacheTTL: 300000, // 5 minutes in milliseconds

  // Behavior
  debug: false,
  showSkeletons: true,

  // Network
  retryAttempts: 3,
  retryDelay: 1000, // 1 second
  timeout: 10000, // 10 seconds

  // Callbacks
  onLoad: (data) => console.log('Loaded:', data),
  onError: (error) => console.error('Error:', error),
  onDataLoaded: (data) => console.log('Rendered:', data)
});

Option Reference

Required Options

OptionTypeDescription
apiUrlstringBase URL for your API (without trailing slash)

Authentication

OptionTypeDefaultDescription
apiKeystring''Your API key (pk_live_* or pk_test_*)

Caching

OptionTypeDefaultDescription
cachebooleantrueEnable localStorage caching
cacheTTLnumber300000Cache time-to-live in milliseconds

Behavior

OptionTypeDefaultDescription
debugbooleanfalseEnable console logging
showSkeletonsbooleantrueShow skeleton loading states

Network

OptionTypeDefaultDescription
retryAttemptsnumber3Number of retry attempts on failure
retryDelaynumber1000Delay between retries (ms)
timeoutnumber10000Request timeout (ms)

Callbacks

OptionTypeDescription
onLoadfunctionCalled after data is loaded from API
onErrorfunctionCalled when an error occurs
onDataLoadedfunctionCalled after data is rendered to DOM

Examples

Development Mode

DBindly.init({
  apiUrl: 'http://localhost:3000/api',
  apiKey: 'pk_test_dev_key',
  cache: false,
  debug: true
});

Production Mode

DBindly.init({
  apiUrl: 'https://dbindly.com/api',
  apiKey: 'pk_live_your_key',
  cache: true,
  cacheTTL: 600000, // 10 minutes
  debug: false
});

With Error Handling

DBindly.init({
  apiUrl: 'https://dbindly.com/api',
  apiKey: 'pk_live_your_key',
  onError: (error) => {
    // Show user-friendly error message
    document.getElementById('error').textContent =
      'Failed to load content. Please refresh the page.';

    // Log to analytics
    analytics.track('DBindly Error', { error: error.message });
  }
});

Public API Methods

After initialization, you can use these methods:

// Load data by ID
const data = await DBindly.load('data-id');

// Fetch data without rendering
const data = await DBindly.fetchData('data-id');

// Fetch multiple items
const items = await DBindly.fetchBatch(['id1', 'id2', 'id3']);

// Fetch collection with pagination
const result = await DBindly.fetchCollection('products', {
  page: 1,
  limit: 20,
  sort: 'price',
  order: 'asc'
});

// Render collection
await DBindly.renderCollection('products', { limit: 10 });

// Clear cache
DBindly.clearCache();

// Get performance metrics
const metrics = DBindly.getMetrics();
console.log(metrics.cacheHitRate, metrics.averageLoadTime);

Next Steps