from typing import Optional
from typing import List
import requests


def query_datamuse_api(word: str, n_rhymes: Optional[int] = None) -> List[str]:
    """Query the DataMuse API.

    Parameters
    ----------
    word : Word to rhyme with
    n_rhymes : Max rhymes to return

    Returns
    -------
    Rhyme words
    """
    out = requests.get(
        "https://api.datamuse.com/words", params={"rel_rhy": word}
    ).json()
    words = [_["word"] for _ in out]
    if n_rhymes is None:
        return words
    return words[:n_rhymes]