That way, the same route class can handle gzip compressed or uncompressed requests.
-```Python hl_lines="8-15"
-{!../../docs_src/custom_request_and_route/tutorial001.py!}
-```
+{* ../../docs_src/custom_request_and_route/tutorial001.py hl[8:15] *}
+
### Create a custom `GzipRoute` class
Here we use it to create a `GzipRequest` from the original request.
-```Python hl_lines="18-26"
-{!../../docs_src/custom_request_and_route/tutorial001.py!}
-```
+
+{* ../../docs_src/custom_request_and_route/tutorial001.py hl[18:26] *}
+
/// note | "Technical Details"
All we need to do is handle the request inside a `try`/`except` block:
-```Python hl_lines="13 15"
-{!../../docs_src/custom_request_and_route/tutorial002.py!}
-```
+
+{* ../../docs_src/custom_request_and_route/tutorial002.py hl[13,15] *}
+
If an exception occurs, the`Request` instance will still be in scope, so we can read and make use of the request body when handling the error:
-```Python hl_lines="16-18"
-{!../../docs_src/custom_request_and_route/tutorial002.py!}
-```
+
+{* ../../docs_src/custom_request_and_route/tutorial002.py hl[16:18] *}
+
+
## Custom `APIRoute` class in a router
You can also set the `route_class` parameter of an `APIRouter`:
-```Python hl_lines="26"
-{!../../docs_src/custom_request_and_route/tutorial003.py!}
-```
+{* ../../docs_src/custom_request_and_route/tutorial003.py hl[26] *}
+
In this example, the *path operations* under the `router` will use the custom `TimedRoute` class, and will have an extra `X-Response-Time` header in the response with the time it took to generate the response:
-```Python hl_lines="13-20"
-{!../../docs_src/custom_request_and_route/tutorial003.py!}
-```
+
+{* ../../docs_src/custom_request_and_route/tutorial003.py hl[13:20] *}