Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add missing parts for rest client docs #1397

Closed
wants to merge 6 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions docs/website/docs/general-usage/http/rest-client.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: RESTClient
description: Learn how to use the RESTClient class to interact with RESTful APIs
keywords: [api, http, rest, request, extract, restclient, client, pagination, json, response, data_selector, session, auth, paginator, jsonresponsepaginator, headerlinkpaginator, offsetpaginator, jsonresponsecursorpaginator, queryparampaginator, bearer, token, authentication]
keywords: [api, http, rest, request, extract, restclient, client, pagination, json, response, data_selector, session, auth, paginator, jsonresponsepaginator, headerlinkpaginator, offsetpaginator, jsonresponsecursorpaginator, queryparampaginator, bearer, token, authentication, reverse etl, json path, openapi, swagger]
---

The `RESTClient` class offers an interface for interacting with RESTful APIs, including features like:
Expand Down Expand Up @@ -80,7 +80,7 @@ For example, if the API response looks like this:
}
```

The `data_selector` should be set to `"posts"` to extract the list of posts from the response.
The `data_selector` should be set to `"posts"` or `"$.posts"` to extract the list of posts from the response.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people are used to use JSONPath starting with $. so this is just to give relation to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but I think if they know JSONPath already they would know that extended syntax anyway. I would try to optimize here for those unfamiliar with JSONPath. We also link JSONPath docs twice for those who need advanced JSONPath.


For a nested structure like this:

Expand All @@ -96,7 +96,7 @@ For a nested structure like this:
}
```

The `data_selector` needs to be set to `"results.posts"`. Read more about [JSONPath syntax](https://github.com/h2non/jsonpath-ng?tab=readme-ov-file#jsonpath-syntax) to learn how to write selectors.
The `data_selector` needs to be set to `"results.posts"` or `"$.results.posts"`. Read more about [JSONPath syntax](https://github.com/h2non/jsonpath-ng?tab=readme-ov-file#jsonpath-syntax) to learn how to write selectors.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for this. Why would we need to have an alternative declaration here?


### PageData

Expand Down Expand Up @@ -432,6 +432,26 @@ for page in client.paginate("/protected/resource"):
print(page)
```

## Common resource defaults

In `RESTAPIConfig` you can provide via `resource_defaults` which will then be applied to all requests

```py
my_params = {
"from_year": 2018,
"end_year": 2024,
}

source_config: RESTAPIConfig = {
"client": {...},
"resource_defaults": {
"endpoint": {
"params": my_params,
}
}
}
```

Comment on lines +442 to +461
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part does not belong to this document. This is documentation for RESTClient and not rest_api.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I will remove it

### API key authentication

API Key Authentication (`ApiKeyAuth`) is an auth method where the client sends an API key in a custom header (e.g. `X-API-Key: <key>`, or as a query parameter).
Expand Down
Loading