Skip to content

Commit 0ca325e

Browse files
committed
feat!: migrate httpx to httpx2
1 parent 50113da commit 0ca325e

94 files changed

Lines changed: 233 additions & 231 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ For a more complete example including more features, see the <a href="https://fa
435435
* **GraphQL** integration with [Strawberry](https://strawberry.rocks) and other libraries.
436436
* Many extra features (thanks to Starlette) such as:
437437
* **WebSockets**
438-
* extremely easy tests based on HTTPX and `pytest`
438+
* extremely easy tests based on HTTPX2 and `pytest`
439439
* **CORS**
440440
* **Cookie Sessions**
441441
* ...and more.
@@ -498,7 +498,7 @@ Used by Pydantic:
498498

499499
Used by Starlette:
500500

501-
* [`httpx`](https://www.python-httpx.org) - Required if you want to use the `TestClient`.
501+
* [`httpx2`](https://pydantic.dev/docs/httpx2/) - Required if you want to use the `TestClient`.
502502
* [`jinja2`](https://jinja.palletsprojects.com) - Required if you want to use the default template configuration.
503503
* [`python-multipart`](https://github.com/Kludex/python-multipart) - Required if you want to support form <dfn title="converting the string that comes from an HTTP request into Python data">"parsing"</dfn>, with `request.form()`.
504504

‎docs/de/docs/advanced/async-tests.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Schauen wir uns an, wie wir das machen können.
1010

1111
Wenn wir in unseren Tests asynchrone Funktionen aufrufen möchten, müssen unsere Testfunktionen asynchron sein. AnyIO stellt hierfür ein nettes Plugin zur Verfügung, mit dem wir festlegen können, dass einige Testfunktionen asynchron aufgerufen werden sollen.
1212

13-
## HTTPX { #httpx }
13+
## HTTPX2 { #httpx2 }
1414

1515
Auch wenn Ihre **FastAPI**-Anwendung normale `def`-Funktionen anstelle von `async def` verwendet, handelt es sich darunter immer noch um eine `async`-Anwendung.
1616

1717
Der `TestClient` betreibt unter der Haube etwas Magie, um die asynchrone FastAPI-Anwendung in Ihren normalen `def`-Testfunktionen, mithilfe von Standard-Pytest aufzurufen. Aber diese Magie funktioniert nicht mehr, wenn wir sie in asynchronen Funktionen verwenden. Durch die asynchrone Ausführung unserer Tests können wir den `TestClient` nicht mehr in unseren Testfunktionen verwenden.
1818

19-
Der `TestClient` basiert auf [HTTPX](https://www.python-httpx.org) und glücklicherweise können wir es direkt verwenden, um die API zu testen.
19+
Der `TestClient` basiert auf [HTTPX2](https://pydantic.dev/docs/httpx2/) und glücklicherweise können wir es direkt verwenden, um die API zu testen.
2020

2121
## Beispiel { #example }
2222

‎docs/de/docs/advanced/openapi-callbacks.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Es könnten nur eine oder zwei Codezeilen sein, wie zum Beispiel:
5151

5252
```Python
5353
callback_url = "https://example.com/api/v1/invoices/events/"
54-
httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
54+
httpx2.post(callback_url, json={"description": "Invoice paid", "paid": True})
5555
```
5656

5757
Der möglicherweise wichtigste Teil des Callbacks besteht jedoch darin, sicherzustellen, dass Ihr API-Benutzer (der externe Entwickler) die *externe API* korrekt implementiert, gemäß den Daten, die *Ihre API* im Requestbody des Callbacks senden wird, usw.
@@ -66,7 +66,7 @@ In diesem Beispiel wird nicht der Callback selbst implementiert (das könnte nur
6666

6767
Der eigentliche Callback ist nur ein HTTP-Request.
6868

69-
Wenn Sie den Callback selbst implementieren, können Sie beispielsweise [HTTPX](https://www.python-httpx.org) oder [Requests](https://requests.readthedocs.io/) verwenden.
69+
Wenn Sie den Callback selbst implementieren, können Sie beispielsweise [HTTPX2](https://pydantic.dev/docs/httpx2/) oder [Requests](https://requests.readthedocs.io/) verwenden.
7070

7171
///
7272

‎docs/de/docs/alternatives.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ Es bietet:
429429
* WebSocket-Unterstützung.
430430
* Hintergrundtasks im selben Prozess.
431431
* Startup- und Shutdown-Events.
432-
* Testclient basierend auf HTTPX.
432+
* Testclient basierend auf HTTPX2.
433433
* CORS, GZip, statische Dateien, Responses streamen.
434434
* Session- und Cookie-Unterstützung.
435435
* 100 % Testabdeckung.

‎docs/de/docs/features.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Mit **FastAPI** bekommen Sie alles von **Starlette** (da FastAPI nur Starlette a
169169
* **WebSocket**-Unterstützung.
170170
* Hintergrundtasks im selben Prozess.
171171
* Startup- und Shutdown-Events.
172-
* Testclient basierend auf HTTPX.
172+
* Testclient basierend auf HTTPX2.
173173
* **CORS**, GZip, statische Dateien, Responses streamen.
174174
* **Sitzungs- und Cookie**-Unterstützung.
175175
* 100 % Testabdeckung.

‎docs/de/docs/index.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Für ein vollständigeres Beispiel, mit weiteren Funktionen, siehe das <a href="
481481
* **GraphQL**-Integration mit [Strawberry](https://strawberry.rocks) und anderen Bibliotheken.
482482
* Viele zusätzliche Features (dank Starlette) wie:
483483
* **WebSockets**
484-
* extrem einfache Tests auf Basis von HTTPX und `pytest`
484+
* extrem einfache Tests auf Basis von HTTPX2 und `pytest`
485485
* **CORS**
486486
* **Cookie-Sessions**
487487
* ... und mehr.
@@ -544,7 +544,7 @@ Verwendet von Pydantic:
544544

545545
Verwendet von Starlette:
546546

547-
* [`httpx`](https://www.python-httpx.org) – erforderlich, wenn Sie den `TestClient` verwenden möchten.
547+
* [`httpx2`](https://pydantic.dev/docs/httpx2/) – erforderlich, wenn Sie den `TestClient` verwenden möchten.
548548
* [`jinja2`](https://jinja.palletsprojects.com) – erforderlich, wenn Sie die Default-Template-Konfiguration verwenden möchten.
549549
* [`python-multipart`](https://github.com/Kludex/python-multipart) – erforderlich, wenn Sie Formulare mittels `request.form()` <dfn title="Konvertieren des Strings, der aus einem HTTP-Request stammt, nach Python-Daten">„parsen“</dfn> möchten.
550550

‎docs/de/docs/tutorial/testing.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
Dank [Starlette](https://starlette.dev/testclient/) ist das Testen von **FastAPI**-Anwendungen einfach und macht Spaß.
44

5-
Es basiert auf [HTTPX](https://www.python-httpx.org), welches wiederum auf der Grundlage von Requests konzipiert wurde, es ist also sehr vertraut und intuitiv.
5+
Es basiert auf [HTTPX2](https://pydantic.dev/docs/httpx2/), welches wiederum auf der Grundlage von Requests konzipiert wurde, es ist also sehr vertraut und intuitiv.
66

77
Damit können Sie [pytest](https://docs.pytest.org/) direkt mit **FastAPI** verwenden.
88

99
## `TestClient` verwenden { #using-testclient }
1010

1111
/// note | Hinweis
1212

13-
Um `TestClient` zu verwenden, installieren Sie zunächst [`httpx`](https://www.python-httpx.org).
13+
Um `TestClient` zu verwenden, installieren Sie zunächst [`httpx2`](https://pydantic.dev/docs/httpx2/).
1414

1515
Fügen Sie es zu Ihrem Projekt hinzu:
1616

1717
```console
18-
$ uv add httpx
18+
$ uv add httpx2
1919
```
2020

2121
///
@@ -26,7 +26,7 @@ Erstellen Sie einen `TestClient`, indem Sie ihm Ihre **FastAPI**-Anwendung über
2626

2727
Erstellen Sie Funktionen mit einem Namen, der mit `test_` beginnt (das ist eine Standard-`pytest`-Konvention).
2828

29-
Verwenden Sie das `TestClient`-Objekt auf die gleiche Weise wie `httpx`.
29+
Verwenden Sie das `TestClient`-Objekt auf die gleiche Weise wie `httpx2`.
3030

3131
Schreiben Sie einfache `assert`-Anweisungen mit den Standard-Python-Ausdrücken, die Sie überprüfen müssen (wiederum, Standard-`pytest`).
3232

@@ -131,7 +131,7 @@ Anschließend könnten Sie `test_main.py` mit den erweiterten Tests aktualisiere
131131
{* ../../docs_src/app_testing/app_b_an_py310/test_main.py *}
132132

133133

134-
Immer wenn der Client Informationen im Request übergeben soll und Sie nicht wissen, wie, können Sie danach suchen (googeln), wie es mit `httpx` gemacht wird, oder sogar, wie es mit `requests` gemacht wird, da das Design von HTTPX auf dem Design von Requests basiert.
134+
Immer wenn der Client Informationen im Request übergeben soll und Sie nicht wissen, wie, können Sie danach suchen (googeln), wie es mit `httpx2` gemacht wird, oder sogar, wie es mit `requests` gemacht wird, da das Design von HTTPX2 auf dem Design von Requests basiert.
135135

136136
Dann machen Sie in Ihren Tests einfach das gleiche.
137137

@@ -143,7 +143,7 @@ Z. B.:
143143
* Um *Header* zu übergeben, verwenden Sie ein `dict` im `headers`-Parameter.
144144
* Für *Cookies* ein `dict` im `cookies`-Parameter.
145145

146-
Weitere Informationen zum Übergeben von Daten an das Backend (mithilfe von `httpx` oder dem `TestClient`) finden Sie in der [HTTPX-Dokumentation](https://www.python-httpx.org).
146+
Weitere Informationen zum Übergeben von Daten an das Backend (mithilfe von `httpx2` oder dem `TestClient`) finden Sie in der [HTTPX2-Dokumentation](https://pydantic.dev/docs/httpx2/).
147147

148148
/// note | Hinweis
149149

‎docs/en/docs/advanced/async-tests.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Let's look at how we can make that work.
1010

1111
If we want to call asynchronous functions in our tests, our test functions have to be asynchronous. AnyIO provides a neat plugin for this, that allows us to specify that some test functions are to be called asynchronously.
1212

13-
## HTTPX { #httpx }
13+
## HTTPX2 { #httpx2 }
1414

1515
Even if your **FastAPI** application uses normal `def` functions instead of `async def`, it is still an `async` application underneath.
1616

1717
The `TestClient` does some magic inside to call the asynchronous FastAPI application in your normal `def` test functions, using standard pytest. But that magic doesn't work anymore when we're using it inside asynchronous functions. By running our tests asynchronously, we can no longer use the `TestClient` inside our test functions.
1818

19-
The `TestClient` is based on [HTTPX](https://www.python-httpx.org), and luckily, we can use it directly to test the API.
19+
The `TestClient` is based on [HTTPX2](https://pydantic.dev/docs/httpx2/), and luckily, we can use it directly to test the API.
2020

2121
## Example { #example }
2222

‎docs/en/docs/advanced/openapi-callbacks.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ It could be just one or two lines of code, like:
5151

5252
```Python
5353
callback_url = "https://example.com/api/v1/invoices/events/"
54-
httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
54+
httpx2.post(callback_url, json={"description": "Invoice paid", "paid": True})
5555
```
5656

5757
But possibly the most important part of the callback is making sure that your API user (the external developer) implements the *external API* correctly, according to the data that *your API* is going to send in the request body of the callback, etc.
@@ -66,7 +66,7 @@ This example doesn't implement the callback itself (that could be just a line of
6666

6767
The actual callback is just an HTTP request.
6868

69-
When implementing the callback yourself, you could use something like [HTTPX](https://www.python-httpx.org) or [Requests](https://requests.readthedocs.io/).
69+
When implementing the callback yourself, you could use something like [HTTPX2](https://pydantic.dev/docs/httpx2/) or [Requests](https://requests.readthedocs.io/).
7070

7171
///
7272

‎docs/en/docs/alternatives.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ It has:
429429
* WebSocket support.
430430
* In-process background tasks.
431431
* Startup and shutdown events.
432-
* Test client built on HTTPX.
432+
* Test client built on HTTPX2.
433433
* CORS, GZip, Static Files, Streaming responses.
434434
* Session and Cookie support.
435435
* 100% test coverage.

0 commit comments

Comments
 (0)