-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Data API dialog Improvements #7578
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JS examples, without jQuery. These examples can be executed:
const params = new URLSearchParams({resource_id: '123-123-123-123'})
const resp = await fetch(
`http://0.0.0.0:5010/api/action/datastore_search?${params}`, {
headers: {authorization: '<API_TOKEN>'}
}
)
await resp.json() const resp = await fetch(`http://0.0.0.0:5010/api/action/datastore_search`, {
method: 'POST',
headers: {
'content-type': 'application/json',
authorization: '<API_TOKEN>'
},
body: JSON.stringify({resource_id: '123-123-123-123', filters: {
subject: ['watershed', 'survey'],
stage: 'active'
}})
})
await resp.json() const resp = await fetch(`http://0.0.0.0:5010/api/action/datastore_search_sql`, {
method: 'POST',
headers: {
'content-type': 'application/json',
authorization: '<API_TOKEN>'
},
body: JSON.stringify({sql: `SELECT * from "123-123-123-123" WHERE title LIKE 'jones'`})
})
await resp.json() Do we want an R example? I suspect that datastore must be especially popular among R users library(httr2)
req <- request("http://0.0.0.0:5010/api/action/")
result <- req %>%
req_url_path_append('datastore_search') %>%
req_headers(Authorization = '<API_TOKEN>') %>%
req_url_query(resource_id = '123-123-123-123', limit = 5, q = 'jones') %>%
req_perform %>%
resp_body_json library(httr2)
req <- request("http://0.0.0.0:5010/api/action/")
result <- req %>%
req_url_path_append('datastore_search') %>%
req_headers(Authorization = '<API_TOKEN>') %>%
req_body_json(list(
resource_id='_table_metadata',
filters = list(
subject = list("watershed", "survey"),
stage = "active"))) %>%
req_perform %>%
resp_body_json
library(httr2)
req <- request("http://0.0.0.0:5010/api/action/")
result <- req %>%
req_url_path_append('datastore_search_sql') %>%
req_headers(Authorization = '<API_TOKEN>') %>%
req_body_json(list(sql="SELECT * from \"123-123-123-123\" WHERE title LIKE 'jones'")) %>%
req_perform %>%
resp_body_json |
very nice. Thank you @smotornyuk |
@smotornyuk I've added your JS and R examples and found an.. interesting.. way of separating the code examples into their own files with jinja2 to hopefully make this easier to maintain and add languages in the future |
This was referenced Jul 3, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #7573
Proposed fixes:
Improve CKAN Data API dialog with syntax highlighting, multiple client languages and jinja2 blocks for expansion
Features: