Test WebSocket connectivity and troubleshoot connection issues with cURL
Limited WebSocket Support: cURL has basic WebSocket support (v7.86+). For full WebSocket functionality, use dedicated clients like Node.js, Python, or PHP.
Since WebSocket requires persistent connections, test the related REST endpoints:
Copy
Ask AI
# Test if the base API is workingcurl -X GET "https://api.byul.ai/api/v2/news?limit=1" \ -H "X-API-Key: byul_api_key" \ -v# Check authenticationcurl -I -X GET "https://api.byul.ai/api/v2/news?limit=1" \ -H "X-API-Key: byul_api_key"
# Test DNS resolutionnslookup api.byul.ai# Alternative DNS testdig api.byul.ai# Test with different DNS serversdig @8.8.8.8 api.byul.aidig @1.1.1.1 api.byul.ai
# Trace network pathtraceroute api.byul.ai# Test specific port connectivitytelnet api.byul.ai 443# Test with timeouttimeout 5 bash -c "</dev/tcp/api.byul.ai/443"
#!/bin/bash# Monitor WebSocket connectivityAPI_KEY="byul_api_key"LOG_FILE="websocket_monitor.log"ALERT_EMAIL="admin@yourcompany.com"monitor_connection() { local timestamp=$(date '+%Y-%m-%d %H:%M:%S') # Test REST API as proxy for service health local status=$(curl -s -o /dev/null -w "%{http_code}" \ -X GET "https://api.byul.ai/api/v2/news?limit=1" \ -H "X-API-Key: $API_KEY") if [ "$status" -eq 200 ]; then echo "[$timestamp] Service healthy" >> $LOG_FILE return 0 else echo "[$timestamp] Service unhealthy (HTTP $status)" >> $LOG_FILE send_alert "Byul API service is down (HTTP $status)" return 1 fi}send_alert() { local message="$1" # Send email alert (requires mail command) echo "Alert: $message" | mail -s "Byul API Alert" "$ALERT_EMAIL" # Or send to Slack (if webhook configured) # curl -X POST -H 'Content-type: application/json' \ # --data "{\"text\":\"$message\"}" \ # "$SLACK_WEBHOOK_URL"}# Run monitoring loopwhile true; do monitor_connection sleep 60 # Check every minutedone
# Install websocat (WebSocket client)curl -L https://github.com/vi/websocat/releases/download/v1.11.0/websocat.x86_64-unknown-linux-musl \ -o websocat && chmod +x websocat# Test with websocatecho '{"type":"auth","apiKey":"byul_api_key"}' | \ ./websocat wss://api.byul.ai/news-v2# Install wscat (Node.js WebSocket client)npm install -g wscat# Test with wscatwscat -c "wss://api.byul.ai/news-v2" \ -H "X-API-Key: byul_api_key"
Recommended Approach: While cURL can test basic connectivity, use dedicated WebSocket clients like websocat, wscat, or programming language-specific libraries for full WebSocket functionality testing.