Skip to content

refactor(server): move REST routing into dedicated RestDispatcher#900

Open
guglielmo-san wants to merge 7 commits intoa2aproject:1.0-devfrom
guglielmo-san:guglielmoc/remove_rest_handler
Open

refactor(server): move REST routing into dedicated RestDispatcher#900
guglielmo-san wants to merge 7 commits intoa2aproject:1.0-devfrom
guglielmo-san:guglielmoc/remove_rest_handler

Conversation

@guglielmo-san
Copy link
Member

@guglielmo-san guglielmo-san commented Mar 25, 2026

Description

This PR centralizes the execution logic for REST endpoints by extracting it from the routing layer (rest_routes.py) into a dedicated RestDispatcher class. It simplifies the pipeline by directly binding the server endpoints to the core RequestHandler.

Fixes #797 🦕

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the server's REST API handling by extracting the core execution logic from the routing layer into a dedicated RestDispatcher class. This change centralizes the processing of REST requests, directly binding server endpoints to the RequestHandler and simplifying the overall API pipeline. The refactoring improves maintainability and clarity by separating concerns, making the system more modular and easier to understand.

Highlights

  • Centralized REST Routing: Introduced a new RestDispatcher class to centralize the execution logic for REST endpoints, moving it out of the routing layer.
  • Removed RESTHandler: The RESTHandler class, which previously contained the REST endpoint logic, has been removed.
  • Simplified rest_routes.py: The rest_routes.py file was refactored to utilize the new RestDispatcher, simplifying the routing setup and improving modularity.
  • Updated validate_version Decorator: Modified the validate_version decorator in helpers.py to remove the implicit self parameter from wrapped function signatures.
  • Comprehensive Testing: Added a new test file with extensive unit tests for the RestDispatcher class, ensuring its correct functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Mar 25, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/routes/rest_routes.py 77.11% 73.53% 🔴 -3.58%
src/a2a/server/routes/rest_dispatcher.py (new) 92.43%
Total 91.47% 91.56% 🟢 +0.10%

Generated by coverage-comment.yml

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the REST API handling by introducing a new RestDispatcher class, replacing the previous RESTHandler. The rest_routes.py file has been updated to utilize this new dispatcher for defining routes, centralizing the dispatch logic. A new test file, test_rest_dispatcher.py, has been added to cover the functionality of the RestDispatcher. Minor adjustments were also made to the validate_version decorator in src/a2a/utils/helpers.py. There is a bug where JSONRPCHandler is exported in src/a2a/server/request_handlers/__init__.py but not imported, which will cause a NameError. Additionally, it is recommended to add tests for successful streaming responses in test_rest_dispatcher.py to ensure robustness.

@guglielmo-san guglielmo-san force-pushed the guglielmoc/remove_rest_handler branch from ebb394c to d66afb1 Compare March 25, 2026 16:24
@guglielmo-san guglielmo-san marked this pull request as ready for review March 25, 2026 16:26
@guglielmo-san guglielmo-san requested a review from a team as a code owner March 25, 2026 16:26


@trace_class(kind=SpanKind.SERVER)
class RestDispatcher:
Copy link
Member

@holtskinner holtskinner Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class RestDispatcher:
class RESTDispatcher:

Not sure if there's a general standard on this, but we should probably keep these acronyms as capitals, like we did for A2A, and how the previous RESTHandler class was setup

@guglielmo-san guglielmo-san enabled auto-merge (squash) March 25, 2026 16:46
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.

2 participants