Crates.io | adoptium_api |
lib.rs | adoptium_api |
version | 0.1.0 |
created_at | 2025-08-03 19:22:26.86033+00 |
updated_at | 2025-08-03 19:22:26.86033+00 |
description | Typed wrapper for a Adoptium REST API |
homepage | |
repository | https://gitlab.com/h45h/adoptium_api |
max_upload_size | |
id | 1780027 |
size | 119,073 |
Small wrapper for a Adoptium REST API.
[!NOTE] All documentation comments are written by a LLM (ChatGPT-3.5/3.0).
all examples can be found in a examples directory and runned via cargo r --example <example_name>
.
use adoptium_api::v3::prelude::*;
// ^
// |
// REST API version which we're using
// Endpoint consists of a 2 things: server and actual endpoint:
let endpoint = Adoptium::production(types::OperationgSystems::new());
// +--------------------+------------------------------+
// | server we're using | actual API endpoint |
You can easily translate any endpoint into a code using explanation below:
Adoptium::production
|
| we've imported "v3" module, so pathes are prefixed with `v3`
| |
| | types::OperatingSystems
| | | |
▼ ▼ ▼ ▼
https://api.adoptium.net/v3/types/operating_systems
Shows how to make simple API call without path and query params.
Run command: cargo r --example fetch_all_supported_operating_systems
File: fetch_all_supported_operating_systems
// Build your request
let endpoint = Adoptium::production(types::OperationgSystems::new());
// Now you can get it's URL
let url = endpoint.try_as_url()?;
println!("URL: {url}");
// Or get a parsed response body if endpoint implements [`GetRequest`] trait.
let response = endpoint.get().await?;
println!("Parsed response: {response:#?}");
Shows how to download a JRE.
Run command: cargo r --example download_jre
File: download_jre.rs
Warning: this example will write files into ./jre_download_output
directory.
// 1. Build the API endpoint for the desired JVM version:
let latest_version_endpoint = assets::Latest::new(DESIRED_VERSION, JvmImpl::Hotspot)
.architecture(ARCHITECTURE)
.os(OPERATING_SYSTEM)
.image_type(IMAGE_TYPE);
// 2. Request the latest version info from Adoptium:
let latest_version_response = Adoptium::production(latest_version_endpoint).get().await?;
// 3. Extract the package download URL from the response:
let version_info = latest_version_response.0.first().expect("No version information found");
let binary = version_info.binary.as_ref().expect("Missing binary information — cannot download");
let package = binary.package.as_ref().expect("Missing package information — cannot download");
let package_url = package.link.as_ref();
// 4. Get decompressed stream of the package archive:
let package_data = reqwest::get(package_url).await?;
let package_data_stream = package_data.bytes_stream().map_err(std::io::Error::other);
let package_data_reader = StreamReader::new(package_data_stream);
let package_data_decoder = GzipDecoder::new(package_data_reader);
// 5. Write all package files from the stream:
tokio_tar::Archive::new(package_data_decoder).unpack(OUTPUT_PATH).await?;
MIT license: feel free to steal, sell, use as a drug, modify, etc.