View Source Wordnik

A library for accessing the Wordnik API

installation

Installation

The package can be installed by adding wordnik to your list of dependencies in mix.exs and running mix.deps.get:

def deps do
  [
    {:wordnik, "~> 1.0.0"}
  ]
end

usage

Usage

The main functions for querying the Wordnik API can be found under the root Wordnik module. Most of what you will need can be found here.

Submodules such as Wordnik.Word.Definitions and Wordnik.Words.RandomWord contain the function they are named for, along with type definitions for query parameters and responses.

Wordnik.Enums contains type definitions for string parameter arguments expecting specific values. These values will be checked at runtime, but are also documented in the typedocs.

Wordnik.Helpers contains functions for returning lists of valid string arguments used in the paramaters mentioned above (dictionaries, parts of speech, etc.). These can be helpful for quickly getting a list of valid options to provide to end users, for example as select options in a UI.

wordnik-api-key

Wordnik API key

To access the Wordnik API, you will need a free API key that can be obtained here.

This key will need to be set as an environmental variable called WORDNIK_API_KEY and the wordnik library will pick it up automatically. If this key is not present the library will alert you with an error tuple:

{:error, "'WORDNIK_API_KEY' could not be loaded from environment"}

sample-query

Sample Query

iex> Wordnik.get_definitions("sublime")
{:ok, definitions_response}

passing-parameters

Passing Parameters

Optional parameters can be passed as a map to queries to help refine them:

iex> Wordnik.get_definitions("sublime", %{
  include_tags: true,
  include_related: true,
  source_dictionaries: "wiktionary,webster",
  limit:  5
})

If no parameters are needed, you can skip the params argument:

iex> Wordnik.get_definitions("sublime")

The parameter fields for each query are based on the Wordnik documentation (linked to below) but follow elixir naming conventions (snake_case). The parameters are also listed in each function's typespecs and documentation. Lastly, parameters pass validation checks and return an error tuple {:error, error_msg} when an invalid parameter is provided.

api-queries

API Queries

The Wordnik package supports the following queries:

word

Word

words

Words

Note: The Reverse Dictionary and Search queries are currently deprecated until the upcoming v5 release of Wordnik. Once the new queries are made available they will be included in the library.