Skip to content

Commit

Permalink
Merge pull request #167 from honeybadger-io/fast-api-example-changes
Browse files Browse the repository at this point in the history
Cleanup the FastAPI examples
  • Loading branch information
roelbondoc authored Apr 9, 2024
2 parents 2f15975 + aafb277 commit c5634eb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,31 @@ Consuming the request body in an ASGI application's middleware is [problematic a

FastAPI allows overriding the logic used by the `Request` and `APIRoute` classes, by [using custom `APIRoute` classes](https://fastapi.tiangolo.com/advanced/custom-request-and-route/). This gives more control over the request body, and makes it possible to send request body data along with honeybadger notifications.

A custom API Route is available at [`honeybadger.contrib.fastapi`](./honeybadger/contrib/fastapi):
A custom API Route is available at [`honeybadger.contrib.fastapi`](./honeybadger/contrib/fastapi).

Here's an example of setting the router class:

```python
from fastapi import FastAPI, APIRouter
from fastapi import FastAPI
from honeybadger import honeybadger
from honeybadger.contrib.fastapi import HoneybadgerRoute

honeybadger.configure(api_key="{{PROJECT_API_KEY}}")
app = FastAPI()
app.router.route_class = HoneybadgerRoute
```

router = APIRouter(route_class=HoneybadgerRoute)
Here's an example of creating a new `APIRouter` instance:

```python
from fastapi import FastAPI, APIRouter
from honeybadger import honeybadger
from honeybadger.contrib.fastapi import HoneybadgerRoute

honeybadger.configure(api_key="{{PROJECT_API_KEY}}")
app = FastAPI()
router = APIRouter(route_class=HoneybadgerRoute)
app.router = router
```

### Starlette
Expand Down

0 comments on commit c5634eb

Please sign in to comment.