#english #word #api #rhyme #api-bindings #datamuse

datamuse-api-rs

A wrapper library for the Datamuse api

3 stable releases

new 2.1.2 Jan 11, 2025
2.1.1 Jan 4, 2025

#530 in Web programming

Download history 243/week @ 2024-12-31 172/week @ 2025-01-07

415 downloads per month

MIT license

44KB
853 lines

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

Dependencies

~7–18MB
~236K SLoC