Skip to content

Conversation

@pydanny
Copy link
Member

@pydanny pydanny commented Oct 16, 2025

Issue(s)

#575

Description

Introduces an optional FastAPI app mounted at '/api' via the new 'fastapi_app' parameter and 'api' property in the Air class. Adds tests to verify API route mounting and response behavior.

This will make it easier for project creators to combine Air and FastAPI, since they are already one project. The api property can be prevented.

Currently state, including lifespan, isn't shared. For reference, it is not easy for this feature to share state.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • New feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Pull request tasks

The following have been completed for this task:

  • [c] Code changes
  • Documentation changes for new or changed features
  • Alterations of behavior come with a working implementation in the examples folder
  • Tests on new or altered behaviors

Demo or screenshot

import air

app = Air()

@app.page
def index() -> air.H1:
    return air.H1("Hello, World!")


@app.api.get("/items")
def get_items():
    return {"items": ["one", "two", "three"]}

Checklist

  • I have run just test and just qa, ensuring my code changes passes all existing tests
  • I have performed a self-review of my own code
  • I have ensured that there are tests to cover my changes

Introduces an optional FastAPI app mounted at '/api' via the new 'fastapi_app' parameter and 'api' property in the Air class. Adds tests to verify API route mounting and response behavior.
@pydanny pydanny added python Pull requests that update python code feature New feature or request labels Oct 16, 2025
@pydanny pydanny linked an issue Oct 16, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

If no routes are attached to the app, it disables itself.
"""
),
] = FastAPI,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be: FastAPI()


self.router.route_class = AirRoute
if fastapi_app is not None:
self.fastapi_app = fastapi_app()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be: = fastapi_app

self.router.route_class = AirRoute
if fastapi_app is not None:
self.fastapi_app = fastapi_app()
self.mount("/api", self.fastapi_app)
Copy link
Collaborator

Choose a reason for hiding this comment

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

"/app" should be customizable.

),
] = None,
path_separator: Annotated[Literal["/", "-"], Doc("An optional path separator.")] = "-",
fastapi_app: Annotated[
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to: api_sub_app

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

Labels

feature New feature or request python Pull requests that update python code Status: Do Not Merge! ❌ Status: In Review 👀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: app.api shortcut to FastAPI

3 participants