✨ Re-export utils from Starlette (#1064)

* ✨ Re-export main features used from Starlette to simplify developer's code

* ♻️ Refactor Starlette exports

* ♻️ Refactor tutorial examples to use re-exported utils from Starlette

* 📝 Add examples for all middlewares

* 📝 Add new docs for middlewares

* 📝 Add examples for custom responses

* 📝 Extend docs for custom responses

* 📝 Update docs and add notes explaining re-exports from Starlette everywhere

* 🍱 Update screenshot for HTTP status

* 🔧 Update MkDocs config with new content

* ♻️ Refactor tests to use re-exported utils from Starlette

* ✨ Re-export WebSocketDisconnect from Starlette for tests

* ✅ Add extra tests for extra re-exported middleware

* ✅ Add tests for re-exported responses from Starlette

* ✨ Add docs about mounting WSGI apps

* ➕ Add Flask as a dependency to test WSGIMiddleware

* ✅ Test WSGIMiddleware example
This commit is contained in:
Sebastián Ramírez authored and GitHub committed 2020-03-01 21:49:20 +01:00
1 parent f2bd2c44e2
commit 0ac9b3ee5c
267 files changed
+1000 -403

No files matched your search

+4 -4
View File
@@ -86,7 +86,7 @@ And another utility to verify if a received password matches the hash stored.
And another one to authenticate and return a user.
```Python hl_lines="7 39 56 57 60 61 70 71 72 73 74 75 76"
```Python hl_lines="7 48 55 56 59 60 69 70 71 72 73 74 75"
{!./src/security/tutorial004.py!}
```
@@ -115,7 +115,7 @@ Define a Pydantic Model that will be used in the token endpoint for the response
Create a utility function to generate a new access token.
```Python hl_lines="3 6 13 14 15 29 30 31 79 80 81 82 83 84 85 86 87"
```Python hl_lines="3 6 12 13 14 28 29 30 78 79 80 81 82 83 84 85 86"
{!./src/security/tutorial004.py!}
```
@@ -127,7 +127,7 @@ Decode the received token, verify it, and return the current user.
If the token is invalid, return an HTTP error right away.
```Python hl_lines="90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107"
```Python hl_lines="89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106"
{!./src/security/tutorial004.py!}
```
@@ -137,7 +137,7 @@ Create a `timedelta` with the expiration time of the token.
Create a real JWT access token and return it.
```Python hl_lines="116 117 118 119 120 121 122 123 124 125 126 127 128 129"
```Python hl_lines="115 116 117 118 119 120 121 122 123 124 125 126 127 128"
{!./src/security/tutorial004.py!}
```
+5 -5
View File
@@ -47,7 +47,7 @@ Now let's use the utilities provided by **FastAPI** to handle this.
First, import `OAuth2PasswordRequestForm`, and use it as a dependency with `Depends` for the path `/token`:
```Python hl_lines="2 75"
```Python hl_lines="2 74"
{!./src/security/tutorial003.py!}
```
@@ -88,7 +88,7 @@ If there is no such user, we return an error saying "incorrect username or passw
For the error, we use the exception `HTTPException`:
```Python hl_lines="1 76 77 78"
```Python hl_lines="1 75 76 77"
{!./src/security/tutorial003.py!}
```
@@ -116,7 +116,7 @@ If your database is stolen, the thief won't have your users' plaintext passwords
So, the thief won't be able to try to use those same passwords in another system (as many users use the same password everywhere, this would be dangerous).
```Python hl_lines="79 80 81 82"
```Python hl_lines="78 79 80 81"
{!./src/security/tutorial003.py!}
```
@@ -154,7 +154,7 @@ For this simple example, we are going to just be completely insecure and return
But for now, let's focus on the specific details we need.
```Python hl_lines="84"
```Python hl_lines="83"
{!./src/security/tutorial003.py!}
```
@@ -179,7 +179,7 @@ Both of these dependencies will just return an HTTP error if the user doesn't ex
So, in our endpoint, we will only get a user if the user exists, was correctly authenticated, and is active:
```Python hl_lines="57 58 59 60 61 62 63 64 65 68 69 70 71 88"
```Python hl_lines="56 57 58 59 60 61 62 63 64 65 67 68 69 70 88"
{!./src/security/tutorial003.py!}
```