datamuse-api-rs

Crates.iodatamuse-api-rs
lib.rsdatamuse-api-rs
version2.1.2
created_at2025-01-04 06:57:31.972723+00
updated_at2025-01-11 04:49:17.424939+00
descriptionA wrapper library for the Datamuse api
homepage
repositoryhttps://github.com/rhymr/datamuse-api-rs
max_upload_size
id1503714
size43,789
(dG9hc3Q)

documentation

README

For more information see the official documentation at https://www.datamuse.com/api/

Examples

Words Endpoint

extern crate tokio;
extern crate datamuse_api_rs;
use datamuse_api_rs::{ DatamuseClient, Vocabulary, EndPoint, RelatedType };

#[tokio::main]
async fn main() -> datamuse_api_rs::Result<()> {
    let client = DatamuseClient::new();
    let request = client.new_query(Vocabulary::English, EndPoint::Words)
        .means_like("breakfast") // The words we're looking for are related to "breakfast"
        .related(RelatedType::Rhyme, "grape"); // and rhyme with "grape"
    let word_list = request.list().await?; // Get the list of words from the api

    assert_eq!("crepe", word_list[0].word); // "crepe" is the only result as of writing this

    Ok(())
}

Suggest Endpoint

extern crate tokio;
extern crate datamuse_api_rs;
use datamuse_api_rs::{ DatamuseClient, Vocabulary, EndPoint };

#[tokio::main]
async fn main() -> datamuse_api_rs::Result<()> {
    let client = DatamuseClient::new();
    let request = client.new_query(Vocabulary::English, EndPoint::Suggest)
        .hint_string("hello wor") // The user has alread typed in "hello wor"
        .max_results(2); // We only want the first 2 results to be returned

    let request = request.build()?; // Build the request
    let response = request.send().await?; // Send the request
    let word_list = response.list()?; // Parse the response into a word_list

    assert_eq!("hello world", word_list[0].word); // "hello world" is the first result as of writing this

    Ok(())
}
OG Credits: slogemann1
Commit count: 13

cargo fmt