Example Usage

Explore practical implementations of eJThB7 features through real-world examples.

Initialization

Initialize the eJThB7 core engine with proper configuration.

npm install @ejthb7/core

Sample Code

import { CoreEngine } from '@ejthb7/core';

const engine = new CoreEngine({
    apiKey: 'YOUR_API_KEY',
    mode: 'development'
});

engine.init().then(() => {
    console.log('Engine ready! 🚀', engine.status);
});
                                    

Authentication

API Key Example

const response = await fetch('https://api.ejthb7.example/data', {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log('Auth response:', data);
                                    

OAuth2 Example

const client = {
    clientId: 'OAUTH_CLIENT_ID',
    clientSecret: 'OAUTH_CLIENT_SECRET',
    redirectUri: 'https://your-app.com/callback'
};

const tokenResponse = await fetch('https://api.ejthb7.com/oauth/token', {
    method: 'POST',
    headers: {
        'Authorization': 'Basic ' + btoa(client.clientId + ':' + client.clientSecret),
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        grant_type: 'authorization_code',
        code: 'RECEIVED_AUTHORIZATION_CODE',
        redirect_uri: client.redirectUri
    })
});
                                    

API Requests

Get User Data

GET /api/v1/user
import axios from 'axios';

const getUser = async () => {
    try {
        const response = await axios.get('https://api.ejthb7.example/api/v1/user', {
            headers: {
                'Authorization': 'Bearer YOUR_JWT_TOKEN'
            }
        });
        console.log('User data:', response.data);
    } catch (error) {
        console.error('API Error:', error.response?.status);
    }
};
                                    

Event Handling

Real-time Stream

Listen to live updates from eJThB7 services using WebSockets.

const ws = new WebSocket('wss://events.ejthb7.example/updates');

ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log('Received:', data.topic, data.payload);
};
                                        

Batch Processing

Process multiple items in a single API call.

const batchResponse = await fetch('https://api.ejthb7.example/batch', {
    method: 'POST',
    headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        operations: [
            { type: 'create', data: { name: 'Alice' } },
            { type: 'update', id: 123, data: { status: 'active' } }
        ]
    })
});
                                        
```