🎁 Rust library crate featuring an API wrapper of the CKAN Action v3 API. https://ckanaction.dathere.com
Find a file
Joel Natividad 661638a406 refactor: change unstable let chains to nested if
cargo t
   Compiling ckanaction v0.1.0 (/Users/joelnatividad/GitHub/ckanaction)
error[E0658]: `let` expressions in this position are unstable
    --> src/lib.rs:1354:12
     |
1354 |         if let Some(custom) = custom_fields
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

error[E0658]: `let` expressions in this position are unstable
    --> src/lib.rs:1983:12
     |
1983 |         if let Some(custom) = custom_fields
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

error[E0658]: `let` expressions in this position are unstable
    --> src/lib.rs:2370:12
     |
2370 |         if let Some(options_obj) = options
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

error[E0658]: `let` expressions in this position are unstable
    --> src/lib.rs:2449:12
     |
2449 |         if let Some(custom) = custom_fields
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `ckanaction` (lib test) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `ckanaction` (lib) due to 4 previous errors
2025-05-27 10:49:09 -04:00
src refactor: change unstable let chains to nested if 2025-05-27 10:49:09 -04:00
.gitignore feat: ckanaction crate implementation with GET actions 2025-04-30 21:49:03 -04:00
Cargo.lock build: remove tokio and bin 2025-05-02 17:17:57 -04:00
Cargo.toml build: remove tokio and bin 2025-05-02 17:17:57 -04:00
README.md docs: add install instructions to README 2025-05-02 16:59:04 -04:00

ckanaction

Rust library crate to access CKAN Action API endpoints through Rust builders. Based on the CKAN Action API v3. Endpoints are expected to return with an output of type serde_json::Value.

cargo add ckanaction

ckanaction IDE hints demo

Examples

Run /package_list endpoint with a limit of 5 results per page and print the output:

use dotenvy::dotenv;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load environment variables from .env file
    dotenv()?;

    // Initialize and build CKAN struct
    let ckan = ckanaction::CKAN::builder()
        .url("http://localhost:5000")
        .token(dotenvy::var("CKAN_API_TOKEN")?)
        .build();

    // Send request to /package_list and print output
    let result = ckan.package_list()
        .limit(5) // <-- This is an optional parameter you can remove
        .call()
        .await?;
    println!("{result:#?}");

    Ok(())
}

The following examples won't include the boilerplate code.

Create a new package (dataset) with custom fields:

let custom_fields = serde_json::json!({
    "data_contact_email": "support@dathere.com",
    "update_frequency": "daily",
    "related_resources": [],
});
let result = ckan.package_create()
    .name("my-new-package".to_string())
    .custom_fields(custom_fields)
    .private(false)
    .call()
    .await?;
println!("{result:#?}");

Create a new resource with a new file from a file path:

let path_buf = current_dir()?.join("data.csv");
let result = ckan
    .resource_create()
    .package_id("3mz0qhbb-cdb0-ewst-x7c0-casnkwv0edub".to_string())
    .name("My new resource".to_string())
    .format("CSV".to_string())
    .upload(path_buf)
    .call()
    .await?;
println!("{result:#?}");

Some endpoints without any parameters may not need a builder such as /status_show so there is no .call() method after .status_show():

let status_show = ckan.status_show().await?;
println!("{status_show:#?}");

Notes

  • If you use a maybe_fn() then if you provide None it will be ignored and that parameter will not be added to the JSON body. This library assumes None would not be provided as a value (since the cases where it is a value is often the default value that the CKAN API already has set for that parameter).