Skip to content

Commit e565cdf

Browse files
authored
Enhance docs on named routes and catch-all route (#257)
1 parent 3c35da1 commit e565cdf

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

docs/guide.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,9 @@ Use the router instance as decorator or context manager to patch `HTTPX` and act
260260
import httpx
261261
import respx
262262

263-
from httpx import Response
264-
265-
266-
api_mock = respx.mock(assert_all_called=False)
267-
api_mock.route(
268-
url="https://api.foo.bar/baz/",
269-
name="baz",
270-
).mock(
271-
return_value=Response(200, json={"name": "baz"}),
263+
api_mock = respx.mock(base_url="https://api.foo.bar/", assert_all_called=False)
264+
api_mock.get("/baz/", name="baz").mock(
265+
return_value=httpx.Response(200, json={"name": "baz"}),
272266
)
273267
...
274268

@@ -286,6 +280,8 @@ def test_ctx_manager():
286280
...
287281
```
288282

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

0 commit comments

Comments
 (0)