Add base router#92
Merged
Merged
Conversation
Co-authored-by: Copilot <copilot@github.com>
…tion; update tests for improved coverage and clarity
…nce type and adjust assertions
…oute setup to directly use TEMPLATE_SERVER_ROUTER
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the FastAPI server architecture to introduce a pluggable, class-based router system and improve modularity, configuration, and testability. The main changes include extracting routing logic into a
BaseRouterabstraction, adding aTemplateServerRouterfor core endpoints, and updating the server and tests to support this new design.API Router Refactor and Modularization
BaseRouterabstract class that encapsulates API route registration, authentication, and rate limiting, enabling routers to be defined as classes rather than functions. (python_template_server/routers/base_router.pypython_template_server/routers/base_router.pyR1-R109)TemplateServerRouterimplementing health and login endpoints, using the new router abstraction. (python_template_server/routers/template_server_router.pypython_template_server/routers/template_server_router.pyR1-R47)TemplateServer) to use a list of routers, which are configured and registered at startup. The oldsetup_routesandadd_routemethods were removed in favor of this new pattern. (python_template_server/template_server.py[1] [2] [3]Configuration and Initialization Improvements
ExampleServerclass now accepts an explicitconfig,config_filepath, andstatic_dir, and exposes aroutersproperty for registering routers. (python_template_server/main.pypython_template_server/main.pyL6-R35)python_template_server/template_server.pypython_template_server/template_server.pyL110-R111)Testing and Fixtures
TemplateServerRouter, including mock rate limiting and configuration, to support the new router-based architecture. (tests/conftest.py[1] [2]Project Organization
python_template_server/routers/__init__.pyto expose router classes for import. (python_template_server/routers/__init__.pypython_template_server/routers/init.pyR1-R6)These changes lay the foundation for a more extensible, maintainable, and testable FastAPI server by decoupling route logic from the main server class and centralizing security and rate limiting concerns in reusable router classes.