/chat/echo

GET ASYNC

Sends simple echo requests to the RAIDA Chat servers and checks the response.

GET /api/v1/chat/echo

Description

This endpoint sends echo requests to all RAIDA Chat servers to check their status and response times. This is useful for testing connectivity to the RAIDA Chat network before making other chat-related API calls.

Note

This is an asynchronous API call. It creates a task and returns its ID. You can query the task status until it completes, showing a progress indicator to the user.

Difference from /echo

While similar to the standard /echo endpoint, this endpoint specifically targets the RAIDA Chat servers rather than the main RAIDA network. Use this endpoint when your application needs to verify connectivity to the chat functionality.

Understanding Asynchronous API Calls

This endpoint is asynchronous, which means:

  1. When you call this endpoint, it immediately returns a task ID rather than waiting for the full operation to complete.
  2. You then need to periodically check the task status using the /api/v1/task/{task_id} endpoint.
  3. Once the task is complete, the task status endpoint will return the full results.
Task Status Response Structure

When checking a task's status, you'll get a JSON response with the following structure:

{
    "id": "task123",              // The task identifier
    "status": "running",          // Status can be "running", "completed", or "error"
    "progress": 60,               // Progress percentage (0-100)
    "message": "...",             // Optional status message or error details
    "data": { ... }               // Only present when status is "completed"
}
Task Status Types

running The task is still in progress. Continue to check the status.

completed The task is finished successfully. The response will include the full result data.

error The task encountered an error. The response will include an error message.

Tip

When displaying task progress to users, consider implementing a progress bar that updates based on the progress value returned by the task status API.

Parameters

This endpoint does not require any parameters.

Response

Returns a 200 OK response with a JSON object containing details about the RAIDA Chat server status.

Response Properties

online integer
Number of RAIDA Chat servers that are online and responded successfully.
pownstring string
String representation of pass/fail status for each RAIDA Chat server. 'p' indicates a pass (server is online), 'f' indicates a fail.
pownarray array of integers
Array representation of pass/fail status for each RAIDA Chat server. '1' indicates a pass (server is online), '0' indicates a fail.
latencies array of integers
Response time in milliseconds for each RAIDA Chat server.

Example Response

{
    "online": 25,
    "pownstring": "ppppppppppppppppppppppppp",
    "pownarray": [
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    ],
    "latencies": [
        1104, 1104, 1417, 1407, 1397, 1416, 1405, 1412, 1397, 1407,
        1406, 1397, 1413, 1412, 1405, 1398, 1413, 1398, 1414, 1397,
        1410, 1404, 1403, 1415, 1113
    ]
}

Examples

JavaScript Example

// Using Fetch API to make the asynchronous call and check task status
const apiHost = 'http://localhost:8004';

// Step 1: Call the chat/echo endpoint to create a task
fetch(`${apiHost}/api/v1/chat/echo`)
    .then(response => response.json())
    .then(task => {
        console.log('Task created:', task);
        
        // Step 2: Monitor task status
        const taskId = task.id;
        const checkTaskInterval = setInterval(() => {
            fetch(`${apiHost}/api/v1/task/${taskId}`)
                .then(response => response.json())
                .then(taskStatus => {
                    console.log(`Task progress: ${taskStatus.progress}%`);
                    
                    // Step 3: Check if the task is complete
                    if (taskStatus.status === 'completed') {
                        clearInterval(checkTaskInterval);
                        const result = taskStatus.data;
                        
                        console.log('RAIDA Chat echo results:');
                        console.log(`Online servers: ${result.online} of 25`);
                        console.log(`Status string: ${result.pownstring}`);
                        console.log('Response times:', result.latencies);
                    } else if (taskStatus.status === 'error') {
                        clearInterval(checkTaskInterval);
                        console.error('Task error:', taskStatus.message);
                    }
                })
                .catch(error => {
                    clearInterval(checkTaskInterval);
                    console.error('Error checking task status:', error);
                });
        }, 1000); // Check every second
    })
    .catch(error => {
        console.error('Error initiating chat echo task:', error);
    });

cURL Example

# Step 1: Call the chat/echo endpoint to create a task
curl -X GET "http://localhost:8004/api/v1/chat/echo" -H "accept: application/json"

# Example response:
# {"id":"task456","status":"running","progress":0}

# Step 2: Check the task status (replace 'task456' with your actual task ID)
curl -X GET "http://localhost:8004/api/v1/task/task456" -H "accept: application/json"

# Example response while in progress:
# {"id":"task456","status":"running","progress":60}

# Example response when complete:
# {"id":"task456","status":"completed","progress":100,"data":{"online":25,"pownstring":"ppppppppppppppppppppppppp","pownarray":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"latencies":[1104,1104,1417,1407,1397,1416,1405,1412,1397,1407,1406,1397,1413,1412,1405,1398,1413,1398,1414,1397,1410,1404,1403,1415,1113]}}