Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example of Modify (redefine) response only to particular endpoint #37

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pavelsr
Copy link

@pavelsr pavelsr commented May 10, 2024

Summary

First off all, Sean @WSH032, thanks for this library

I added one more example to Advanced usage

My example can be useful for API A/B testing or hiding particular methods of upstream

Close: #36

Checklist

  • I've read CONTRIBUTING.md.
  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

from starlette.requests import Request
from fastapi_proxy_lib.core.http import ReverseHttpProxy

app = FastAPI()
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps adding lifespan would be better?

app = FastAPI(lifespan=close_proxy_event)

from fastapi_proxy_lib.core.http import ReverseHttpProxy

app = FastAPI()
proxy = ReverseHttpProxy(base_url="https://httpbin.org/")
Copy link
Owner

Choose a reason for hiding this comment

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

Comment on lines +132 to +135

@app.get("/{path:path}")
async def _(request: Request, path: str = ""):
if path == "ip" and request.method == "GET":
Copy link
Owner

Choose a reason for hiding this comment

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

Can we add @app.post("/{path:path}") here? Because I see below there's a check for request.method == "GET".

@WSH032
Copy link
Owner

WSH032 commented May 10, 2024

Hi @pavelsr ! Well done! 🎉 Every pull request targeting the documentation is appreciated! Thank you for your contribution!

I have left some reviews, could you take a look at them?

The CI pipeline encountered some errors, but don't worry, I'll fix it.

@WSH032 WSH032 changed the title Add example of redefining particular endpoint docs: add example of Modify (redefine) response only to particular endpoint May 10, 2024
@WSH032
Copy link
Owner

WSH032 commented May 11, 2024

The CI pipeline encountered some issues from the upstream (codecov/feedback#358).

#28 Upgrading to codecov-action v4 might resolve this issue. I'll test it out and see if the upgrade works.

Copy link

codecov bot commented May 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.74%. Comparing base (977d9c1) to head (c8533aa).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #37   +/-   ##
=======================================
  Coverage   96.74%   96.74%           
=======================================
  Files           9        9           
  Lines         461      461           
  Branches       67       67           
=======================================
  Hits          446      446           
  Misses          9        9           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 example of redefining particular endpoint
2 participants