From 53aa2ac99e97b2bb395e3afff893eeda9a72b87e Mon Sep 17 00:00:00 2001 From: Anton Burnashev Date: Tue, 26 Mar 2024 19:17:43 +0300 Subject: [PATCH] Use `py` for the code blocks --- docs/website/docs/general-usage/rest-client.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/website/docs/general-usage/rest-client.md b/docs/website/docs/general-usage/rest-client.md index 2565871996..1bf219dc12 100644 --- a/docs/website/docs/general-usage/rest-client.md +++ b/docs/website/docs/general-usage/rest-client.md @@ -18,7 +18,7 @@ This guide demonstrates how to use the `RESTClient` class to read data APIs focu Here's a simple pipeline that reads issues from the [dlt GitHub repository](https://github.com/dlt-hub/dlt/issues). The API endpoint is `https://api.github.com/repos/dlt-hub/dlt/issues`. The result is "paginated", meaning that the API returns a limited number of issues per page. The `paginate()` iterates over all pages and yields the results which are then processed by the pipeline. -```python +```py import dlt from dlt.sources.helpers.rest_client import RESTClient @@ -68,7 +68,7 @@ The `RESTClient` class is initialized with parameters that define its behavior f To perform basic GET and POST requests, use the get() and post() methods respectively. This works similarly to the requests library: -```python +```py client = RESTClient(base_url="https://api.example.com") response = client.get("/posts/1") ``` @@ -77,7 +77,7 @@ response = client.get("/posts/1") The `RESTClient.paginate()` method is specifically designed to handle paginated responses, yielding `PageData` objects for each page: -```python +```py for page in client.paginate("/posts"): print(page) ``` @@ -114,7 +114,7 @@ The available authentication methods are: RESTClient.paginate() allows to specify a custom hook function that can be used to modify the response objects. For example, to handle specific HTTP status codes gracefully: -```python +```py def custom_response_handler(response): if response.status_code == 404: # Handle not found @@ -129,7 +129,7 @@ The handler function may raise `IgnoreResponseException` to exit the pagination The `paginate()` helper function provides a shorthand for paginating API responses. It takes the same parameters as the `RESTClient.paginate()` method but automatically creates a RESTClient instance with the specified base URL: -```python +```py from dlt.sources.helpers.requests import paginate for page in paginate("https://api.example.com/posts"):