Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(realtime): add explicit REST API call for broadcast #1256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
grdsdev wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from feat/realtime-explicit-rest-call

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
Copy link

Pull Request Test Coverage Report for Build 18695423238

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 72 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.02%) to 93.906%

Files with Coverage Reduction New Missed Lines %
src/postgrest/base_request_builder.py 6 91.15%
src/postgrest/_sync/request_builder.py 11 90.84%
src/postgrest/_async/request_builder.py 11 90.84%
src/realtime/_async/channel.py 44 75.2%
Totals Coverage Status
Change from base Build 18355756900: -0.02%
Covered Lines: 8829
Relevant Lines: 9402

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /