Skip to content

feat: fastapi integration added. - #137

Open
lbukr wants to merge 1 commit into
dapper91:devfrom
lbukr:fastapi
Open

feat: fastapi integration added.#137
lbukr wants to merge 1 commit into
dapper91:devfrom
lbukr:fastapi

Conversation

@lbukr

@lbukr lbukr commented Jul 18, 2026

Copy link
Copy Markdown

Implementation of fastapi server based

Comment thread pyproject.toml
Comment thread pyproject.toml Outdated

jsonrpc_app = integration.Application('/api/v1')
jsonrpc_app.add_methods(methods)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it worth to define a fastapi app variable like:

app = jsonrpc_app.http_app

to be able to start it with fastapi dev or fastapi run command.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

A more useful example is

jsonrpc_app = integration.Application('/api/v1')
jsonrpc_app.add_methods(methods)

app = fastapi.FastAPI()
app.mount("/rpc", jsonrpc_app.http_app)

The same example is described in openapi + fastapi docs

Comment thread pjrpc/server/integration/fastapi.py Outdated
if annotation is None:
return False

return inspect.isclass(annotation) and issubclass(annotation, fastapi.Request)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

fastapi request is a generic type so inspect.isclass always returns False. We must check the origin of the type not the type itself:

def is_fastapi_request(idx: int, name: str, annotation: Optional[type[Any]], default: Optional[Any]) -> bool:
    if annotation is None:
        return False

    annotation_origin = typing.get_origin(annotation)
    return inspect.isclass(annotation_origin) and issubclass(annotation_origin, fastapi.Request)

"""
Creates a user.

:param request: http request

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

http request is not passed. Let's pass it with to make the example more fulfilling:

@methods.add(
    pass_context=True,
    metadata=[
        openapi.metadata(
            summary="Creates a user",
            tags=['users'],
            errors=[AlreadyExistsError],
        ),
    ],
)
def add_user(request: fastapi.Request[Mapping[str, Any]], user: UserIn) -> UserOut:
    """
    Creates a user.

    :param request: http request
    :param object user: user data
    :return object: registered user
    :raise AlreadyExistsError: user already exists
    """

@lbukr lbukr changed the title fastapi integration added. feat: fastapi integration added. Jul 25, 2026
@dapper91

Copy link
Copy Markdown
Owner

aiohttp 3.14 and aioresponses compatibility is broken pnuckowski/aioresponses#289

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