Expand description
Ferinth
Ferinth is a simple library for using the Modrinth API in Rust projects. It uses Reqwest as its HTTPS client and deserialises responses to strongly typed structs using SerDe.
Features
This crate includes the following:
- All structure definitions based on https://github.com/modrinth/labrinth/wiki/API-Documentation#structure-definitions
- Includes the following API calls:
- Get mod by mod ID
- List mod categories
- List mod loaders
- List game versions
- Get user by user ID
- List team members by team ID
- Get version by version ID
- Get version by file hash
- List versions by mod ID
- Download version file
URL traversal is blocked because all IDs are verified.
assert!(modrinth.get_mod("sodium/version").await.is_err());
This crate uses Rustls rather than OpenSSL, because OpenSSL is outdated and slower.
The following features have not yet been implemented
- Search mods
- User authentication
- Get current user (constrained by the lack of user authentication)
Unfortunately, I am not planning to implement any of these features in this first version due to poor documentation. I will add these features in the next version, version 2, once the Modrinth API v2 rolls out.
Example (and Tutorial)
The full source code for this can be found as a binary project at example/.
In this example, we are going to download and install the latest version of Sodium.
// First, let's initialise the API
// You should replace 'example' with your application's name
let api = Ferinth::new("example");
// Now, lets get the Sodium mod
// You can use the mod ID, or the mod slug
// The mod ID will never change but the mod slug can change at anytime
// Using the mod slug
let sodium = api.get_mod("sodium").await?;
// Using the mod ID
let sodium = api.get_mod("AANobbMI").await?;
// Now lets get the versions that the Sodium mod has
let sodium_versions = api.list_versions("AANobbMI").await?;
// The versions are sorted chronologically so the first element should be the latest one
let latest_version = &sodium_versions[0];
// And now we can get this version's mod file, which is called a version file
let version_file = &latest_version.files[0];
// Then we can download this version file
let contents = api.download_version_file(version_file).await?;
// And next, lets open the file we want to write this to
let mut mod_file = File::create("Sodium.jar")?;
// And finally, we can write the contents to mod_file
mod_file.write_all(&contents)?;
// Now you can use load the JAR file using a mod loader. To play Sodium. you should use Fabric
Modules
Structs
An instance of the API to invoke API calls on.