Skip to content

Revised PR 763 - Add API key support for JSON-RPC requests #827

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshuahamsa
Copy link

Revised PR 763
#763

This change allows JsonRpcBase to include custom HTTP headers when connecting to XRPL nodes that require authentication or metadata. The __init__ method now accepts a headers argument, which is stored as an attribute and merged with any per-request headers passed to _request_impl.
• Updated the _request_impl method to merge default and request-specific headers.
• Added a headers parameter to the __init__ method for flexible instantiation.
• This change was tested by connecting to a private XRPL server that required authentication using a custom header.

High Level Overview of Change

This PR introduces support for custom header injection in the JsonRpcBase class. An optional headers parameter has been added to the __init__ method, allowing users to specify HTTP headers to include in each JSON-RPC request. The _request_impl method also accepts an optional headers argument to override or add headers on a per-request basis.

This makes it easier to integrate xrpl-py with private infrastructure providers and secure environments, while maintaining full backward compatibility.

Context of Change

This change is driven by the increasing use of XRPL infrastructure that relies on API key or header-based authentication—such as rate-limited services or internal infrastructure. Previously, JsonRpcBase did not support adding HTTP headers, limiting its usefulness in many production environments.

By making this update in the shared json_rpc_base.py layer, all inheriting classes benefit from the new feature. It allows for greater flexibility without impacting users who do not require any headers. Additionally, the per-request header support allows for advanced use cases like dynamic tokens, session headers, or monetized access.

Type of Change

  • New feature (non-breaking change which adds functionality)

Did you update CHANGELOG.md?

  • Yes
  • No, this change does not impact library users

Test Plan

The change can be tested by:
• Connecting to a private XRPL server that requires authentication using a custom header and verifying that requests are processed successfully.
• Ensuring compatibility with public nodes by omitting the headers parameter, confirming that no issues arise when using unauthenticated connections.
• Passing request-specific headers to _request_impl and verifying that they are correctly merged with any global headers.
• Confirming that all existing requests function identically when headers are not used.

Future Tasks

Future tasks related to this PR could include:
• Elevating header support to the top-level Client class to ensure WebSocket clients can also benefit from custom headers.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

The update introduces a new optional parameter, headers, in the JsonRpcBase class. This parameter allows for the inclusion of custom HTTP headers during initialization and on a per-request basis. It enables connections to XRPL nodes that require additional authentication methods such as API keys or Dhali payment-claim headers. The change is documented in the CHANGELOG.md file and updates the exported public entities to reflect the enhanced functionality.

Changes

Files Change Summary
CHANGELOG.md, JsonRpcBase Added a headers parameter to JsonRpcBase to support custom HTTP headers. This facilitates API key authentication and Dhali payment-claim headers on initialization and on a per-request basis.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant J as JsonRpcBase
    participant N as XRPL Node

    C->>J: Initialize with custom headers
    C->>J: Send JSON-RPC request (optionally with per-request headers)
    J->>N: Forward request including headers
    N-->>J: Return response
    J-->>C: Deliver response
Loading

Poem

I'm a rabbit in a code-filled maze,
Hopping through headers in bright arrays,
Custom HTTP magic, swift and keen,
Connecting securely, smooth and serene,
In lines of code, my joy is seen!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 109c413 and 94dcefc.

📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
🔇 Additional comments (1)
CHANGELOG.md (1)

24-24: Clear Documentation Update for Custom HTTP Header Support

This changelog entry clearly documents the new support for custom HTTP headers in the JsonRpcBase class via the headers parameter. The note specifies that headers can be set at initialization and/or on a per-request basis, which aligns well with the PR objectives needed for authenticated connections to XRPL nodes.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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