Skip to content

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Oct 9, 2025

🔍 Description

This PR ports the feature from supabase-js#1751 to add explicit REST API support for broadcast messages in the Python realtime library.

What changed?

  • New method http_send(): Added a new public method to AsyncRealtimeChannel that explicitly uses the REST API for broadcast messages, regardless of WebSocket connection state
  • Deprecation warning: Added a warning log when send_broadcast() is called while not connected, alerting users about the implicit behavior
  • New dependency: Added httpx[http2] to enable HTTP requests for the REST API calls
  • Comprehensive tests: Added 12 new test cases covering all aspects of the http_send() functionality

Why was this change needed?

The current approach can lead users to use broadcast without understanding the underlying mechanism. By providing an explicit http_send() method, users have more control over how their messages are delivered:

  • Explicit REST delivery: Users can guarantee REST API usage when they need it
  • Better migration path: Helps users gradually migrate from implicit REST fallback to explicit REST calls
  • Improved visibility: The deprecation warning makes users aware when they're using REST vs WebSocket

🔄 Breaking changes

  • ⚠️ New deprecation warning logged when using send_broadcast() while not connected
    • This is logged as a warning and doesn't break existing functionality
    • Users are encouraged to migrate to http_send() for explicit REST delivery

📋 Checklist

🧪 Test plan

The PR includes comprehensive test coverage:

  • Test http_send() with and without access tokens
  • Test payload validation (rejects when payload is None)
  • Test timeout handling
  • Test error handling for non-202 status codes
  • Test error message extraction from response body
  • Test custom timeout configuration
  • Test private channel support
  • Test correct payload structure
  • Test deprecation warning in send_broadcast()

All tests pass: pytest tests/test_http_send.py -v

📚 Related

🤖 Generated with Claude Code

Added new public method `http_send` for explicit usage of REST API for broadcast messages.
This method always uses the REST API endpoint regardless of WebSocket connection state,
giving users more control over message delivery.

Changes:
- Add `http_send()` method to AsyncRealtimeChannel for explicit REST delivery
- Add deprecation warning to `send_broadcast()` when falling back to REST
- Add httpx dependency for REST API calls
- Add comprehensive test suite for http_send functionality

Ported from supabase-js PR #1751

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@grdsdev grdsdev marked this pull request as draft October 9, 2025 17:50
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