Skip to content

rhymr/datamuse-api-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%