Skip to content

API Endpoint Generator Feature#5

Merged
GeorgeBPrice merged 1 commit into
mainfrom
exposed-api-endpoint-feature
Jul 4, 2025
Merged

API Endpoint Generator Feature#5
GeorgeBPrice merged 1 commit into
mainfrom
exposed-api-endpoint-feature

Conversation

@GeorgeBPrice
Copy link
Copy Markdown
Owner

External API Feature

Overview

This merge request implements a comprehensive external API system for AI Mocker, allowing authenticated users to generate mock data programmatically via API keys. The feature includes secure API key management, rate limiting, and clean data extraction for seamless integration.

Features Added

API Key Management System

  • Secure API Key Generation: PBKDF2 hashing with unique salt per key
  • 90-Day Expiry: Automatic expiration for security
  • Multi-User Support: Each user can create multiple API keys
  • Usage Tracking: Monitor API key usage and last accessed times
  • Key Revocation: Users can revoke keys at any time

External API Endpoint

  • POST /api/v1/generate: Main endpoint for mock data generation
  • Bearer Token Authentication: Secure API key validation
  • Clean Data Response: Extracts records without explanatory text
  • Multiple Formats: JSON, SQL, CSV, XML, HTML, TXT support
  • Rate Limiting: 5 generations per day (free tier)

Security Features

  • PBKDF2 Hashing: Cryptographically secure key storage
  • Salt Per Key: Unique salt prevents rainbow table attacks
  • Timing-Safe Comparison: Prevents timing attacks
  • No Hash Exposure: Secure validation without exposing hashes

Web Interface

  • API Keys Management Page: Dedicated page at /api-keys
  • Key Creation Dialog: User-friendly key generation
  • Key Listing: View all active keys with usage stats
  • Key Revocation: One-click key deletion
  • Documentation: Built-in API documentation and examples

Authentication Flow

  1. Extract Bearer token from Authorization header
  2. Validate API key against all stored keys (5 min cached) using PBKDF2
  3. Check expiration and return user/key information
  4. Update usage statistics on successful validation

API Usage Examples

Basic Request

curl -X POST https://our-domain.com/api/v1/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "schema": " users (id INT, name VARCHAR(100), email VARCHAR(255))",
    "count": 5,
    "format": "json"
  }'

Response Format

{
  "success": true,
  "result": "[{\"id\": 1, \"name\": \"John Doe\", \"email\": \"john@example.com\"}]",
  "usage": {
    "limit": 5,
    "remaining": 4,
    "resetTimestamp": 1704067200
  }
}

Monitoring & Analytics

Usage Tracking

  • API key usage counts and last accessed times
  • Daily rate limit tracking
  • Generation events logged for analytics

Debug Endpoints (Development Only)

  • /api/debug/api-key: Test API key validation
  • /api/debug/test-validation: Validate specific keys
  • /api/debug/list-keys: List all keys (admin only)

Documentation

Generated Documentation

  • API Documentation: docs/EXTERNAL_API.md
  • Postman Collection: docs/AI_Mocker_API.postman_collection.json
  • Quick Reference: docs/API_EXAMPLES.md

Web Interface Documentation

  • Built-in code examples for each format
  • Copy-paste ready cURL commands
  • Interactive API key management

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
ai-mocker ⬜️ Ignored (Inspect) Jul 4, 2025 7:09am

@GeorgeBPrice
Copy link
Copy Markdown
Owner Author

New Feature - Generate Mock Records via API

Implemented a comprehensive external API system for AI Mocker, allowing authenticated users to generate mock data programmatically via API keys. The feature includes secure API key management, rate limiting, and clean data extraction for seamless integration.

@GeorgeBPrice GeorgeBPrice merged commit d4631c1 into main Jul 4, 2025
3 checks passed
@GeorgeBPrice GeorgeBPrice deleted the exposed-api-endpoint-feature branch July 4, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant