Skip to content

feat: add FastAPI integration example#19

Merged
AryanSharma48 merged 2 commits into
AryanSharma48:mainfrom
aaishmeen:feature/fastapi-example
Jun 26, 2026
Merged

feat: add FastAPI integration example#19
AryanSharma48 merged 2 commits into
AryanSharma48:mainfrom
aaishmeen:feature/fastapi-example

Conversation

@aaishmeen

@aaishmeen aaishmeen commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a FastAPI integration example under examples/fastapi to demonstrate how SmoothAPI can be integrated into a FastAPI application.

The example showcases the library's core resilience features, including retry handling, circuit breaker behavior, and fallback responses, while using the existing sandbox server for demonstration. It also includes a README.md with setup instructions and a requirements.txt file for installing the required dependencies.

Affected files:

  • examples/fastapi/main.py
  • examples/fastapi/README.md
  • examples/fastapi/requirements.txt

Fixes #10

Summary by CodeRabbit

  • New Features

    • Added a complete FastAPI example showing retry handling, circuit breaker behavior, and fallback responses.
    • Included a new README with setup steps, endpoint descriptions, and run instructions.
    • Updated package metadata to version 1.1.0.
    • Enabled JSON module imports in the TypeScript project configuration.
  • Bug Fixes

    • Improved the FastAPI example’s request lifecycle handling by ensuring the shared HTTP client closes cleanly on shutdown.

@AryanSharma48

Copy link
Copy Markdown
Owner

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue 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 rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@AryanSharma48

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f84f169-55ff-4e1b-8643-759aeb48b15a

📥 Commits

Reviewing files that changed from the base of the PR and between bed3792 and fa0e7c4.

📒 Files selected for processing (3)
  • examples/fastapi/main.py
  • packages/smooth-api-py/pyproject.toml
  • packages/smooth-api-ts/tsconfig.json
✅ Files skipped from review due to trivial changes (1)
  • packages/smooth-api-py/pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/fastapi/main.py

📝 Walkthrough

Walkthrough

Adds a FastAPI example app and README for SmoothAPI retry and circuit-breaker demos, with shared async client setup, demo routes, example dependencies, a package version bump, and a TypeScript JSON module import setting.

Changes

FastAPI integration example

Layer / File(s) Summary
Example scaffold and setup
examples/fastapi/main.py, examples/fastapi/requirements.txt, examples/fastapi/README.md
FastAPI app metadata, shared async client lifecycle, resilience configs, example dependencies, and README setup instructions are added.
Routes overview and retry demo
examples/fastapi/main.py
The root endpoint lists the demo routes, and /retry-demo calls fetch_unstable_data() through @resilient_api(retry_config) and returns the upstream JSON result.
Circuit breaker demo route
examples/fastapi/main.py
fetch_failing_data() calls GET {SANDBOX_URL}/always-fail through @resilient_api(circuit_config), and /circuit-demo returns response details or fallback data.
Release metadata and import config
packages/smooth-api-py/pyproject.toml, packages/smooth-api-ts/tsconfig.json
The Python package version is updated to 1.1.0, and resolveJsonModule is enabled in the TypeScript compiler options.

Sequence Diagram(s)

Retry demo flow

sequenceDiagram
  participant RetryDemo as "retry_demo()"
  participant FetchUnstable as "fetch_unstable_data()"
  participant ResilientRetry as "`@resilient_api`(retry_config)"
  participant HttpClient as "http_client"
  participant Sandbox as "GET {SANDBOX_URL}/unstable-data"
  RetryDemo->>FetchUnstable: call
  FetchUnstable->>ResilientRetry: wrap request
  ResilientRetry->>HttpClient: send GET
  HttpClient->>Sandbox: request unstable data
  Sandbox-->>HttpClient: JSON body
  HttpClient-->>ResilientRetry: httpx response
  ResilientRetry-->>RetryDemo: upstream JSON
Loading

Circuit breaker demo flow

sequenceDiagram
  participant CircuitDemo as "circuit_demo()"
  participant FetchFailing as "fetch_failing_data()"
  participant ResilientCircuit as "`@resilient_api`(circuit_config)"
  participant HttpClient as "http_client"
  participant Sandbox as "GET {SANDBOX_URL}/always-fail"
  CircuitDemo->>FetchFailing: call
  FetchFailing->>ResilientCircuit: wrap request
  ResilientCircuit->>HttpClient: send GET
  HttpClient->>Sandbox: request failing data
  Sandbox-->>HttpClient: error response
  alt httpx.Response returned
    ResilientCircuit-->>CircuitDemo: httpx.Response
    CircuitDemo->>CircuitDemo: return status_code and result.json()
  else fallback data returned
    ResilientCircuit-->>CircuitDemo: fallback payload
    CircuitDemo->>CircuitDemo: return fallback result
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A bunny hopped through FastAPI night,
With retries and breakers all snug and bright.
I twitched my nose at JSON and grace,
Then left a wee thump in the build-space.
Hoppity-hop, the demo's just right! 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes package versioning and TypeScript config, which are unrelated to the FastAPI example scope. Remove the unrelated version and tsconfig edits, or justify them in the issue if they are intentionally part of the example work.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: adding a FastAPI integration example.
Linked Issues check ✅ Passed The PR adds the FastAPI example, README, and dependencies while demonstrating retries, circuit breaker, fallback, and route integration.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…nfig

Co-authored-by: aaishmeen <chowdharyaaiishmeen@gmail.com>
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@AryanSharma48 is attempting to deploy a commit to the aryansharma48's projects Team on Vercel.

A member of the Team first needs to authorize it.

@AryanSharma48
AryanSharma48 merged commit 0321f5b into AryanSharma48:main Jun 26, 2026
6 of 7 checks passed
@aaishmeen
aaishmeen deleted the feature/fastapi-example branch June 27, 2026 17:42
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.

Add FastAPI Integration Example

2 participants