Skip to content

Commit

Permalink
Enhance docs on named routes and catch-all route (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Mar 19, 2024
1 parent 3c35da1 commit e565cdf
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,9 @@ Use the router instance as decorator or context manager to patch `HTTPX` and act
import httpx
import respx

from httpx import Response


api_mock = respx.mock(assert_all_called=False)
api_mock.route(
url="https://api.foo.bar/baz/",
name="baz",
).mock(
return_value=Response(200, json={"name": "baz"}),
api_mock = respx.mock(base_url="https://api.foo.bar/", assert_all_called=False)
api_mock.get("/baz/", name="baz").mock(
return_value=httpx.Response(200, json={"name": "baz"}),
)
...

Expand All @@ -286,6 +280,8 @@ def test_ctx_manager():
...
```

!!! tip "Catch-all"
Add a *catch-all* route last as a fallback for any non-matching request, e.g. `api_mock.route().respond(404)`.
!!! note "NOTE"
Named routes in a *reusable router* can be directly accessed via `my_mock_router[<route name>]`

Expand Down

0 comments on commit e565cdf

Please sign in to comment.