adoptium_api
Small wrapper for a Adoptium REST API.
[!NOTE] All documentation comments are written by a LLM (ChatGPT-3.5/3.0).
Examples
all examples can be found in a examples directory and runned via cargo r --example <example_name>.
How endpoints are built
use *;
// ^
// |
// REST API version which we're using
// Endpoint consists of a 2 things: server and actual endpoint:
let endpoint = production;
// +--------------------+------------------------------+
// | 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
Basic
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 = production;
// Now you can get it's URL
let url = endpoint.try_as_url?;
println!;
// Or get a parsed response body if endpoint implements [`GetRequest`] trait.
let response = endpoint.get.await?;
println!;
JRE downloader
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 = new
.architecture
.os
.image_type;
// 2. Request the latest version info from Adoptium:
let latest_version_response = production.get.await?;
// 3. Extract the package download URL from the response:
let version_info = latest_version_response.0.first.expect;
let binary = version_info.binary.as_ref.expect;
let package = binary.package.as_ref.expect;
let package_url = package.link.as_ref;
// 4. Get decompressed stream of the package archive:
let package_data = get.await?;
let package_data_stream = package_data.bytes_stream.map_err;
let package_data_reader = new;
let package_data_decoder = new;
// 5. Write all package files from the stream:
new.unpack.await?;
TODO
- Handle redirects.
- More robust errors.
License
MIT license: feel free to steal, sell, use as a drug, modify, etc.