docs: improve examples and clarification about status_show

This commit is contained in:
rzmk 2025-05-01 15:53:09 -04:00
parent 8f888e96e1
commit 02915feb1c
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ Rust library crate to access CKAN Action API endpoints through Rust builders. Ba
## Examples ## Examples
Run `/status_show` endpoint for a CKAN instance and print the output: Run `/package_list` endpoint with a limit of 5 results per page and print the output:
```rust ```rust
use dotenvy::dotenv; use dotenvy::dotenv;
@ -20,9 +20,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.token(dotenvy::var("CKAN_API_TOKEN")?) .token(dotenvy::var("CKAN_API_TOKEN")?)
.build(); .build();
// Send request to /status_show and print output // Send request to /package_list and print output
let status_show = ckan.status_show().await?; let result = ckan.package_list()
println!("{status_show:#?}"); .limit(5) // <-- This is an optional parameter you can remove
.call()
.await?;
println!("{result:#?}");
Ok(()) Ok(())
} }
@ -30,13 +33,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
> The following examples won't include the boilerplate code. > The following examples won't include the boilerplate code.
List packages:
```rust
let result = ckan.package_list().call().await?;
println!("{result:#?}");
```
Create a new package (dataset) with custom fields: Create a new package (dataset) with custom fields:
```rust ```rust
@ -69,6 +65,13 @@ let result = ckan
println!("{result:#?}"); println!("{result:#?}");
``` ```
Some endpoints without any parameters may not need a builder such as `/status_show` so there is no need to run `.call()` on `.status_show()`:
```rust
let status_show = ckan.status_show().await?;
println!("{status_show:#?}");
```
## Notes ## Notes
- Add the `CKAN_API_TOKEN` environment variable to a `.env` file where the program runs to include the token when making requests to the CKAN API. - Add the `CKAN_API_TOKEN` environment variable to a `.env` file where the program runs to include the token when making requests to the CKAN API.