2013-03-20 16:17:04 -07:00
..
2012-10-05 21:08:55 -07:00
2012-10-06 05:56:52 +02:00
2013-03-20 16:17:04 -07:00

Wordnik Java client library

Overview

This is a full client library for the Wordnik API. It requires that you have a valid Wordnik API Key--you can get one for free at http://developer.wordnik.com.

This library is built using the Wordnik Swagger client library generator. You can re-generate this library by running ./bin/java-wordnik-api.sh from the swagger-codegen project

Usage

Generate the client library with Maven:

mvn package

Add the library to your project and you're ready to go:

import com.wordnik.client.api.*;
import com.wordnik.client.model.*;

import com.wordnik.client.common.ApiException;

import java.util.List;

public class Test {
	public static void main(String[] args) {
		if(args.length == 0) {
			System.out.println("Pass your API key as an argument");
			System.exit(0);
		}
		String key = args[0];

		try {
			WordApi api = new WordApi();
			api.getInvoker().addDefaultHeader("api_key", key);
			List<Definition> definitions = api.getDefinitions(
				"Cat", 				//  word
				"noun",				//  only get definitions which are "nouns"
				"wiktionary", // 	use wiktionary
				3,						//	fetch only 3 results max
				"true",				//	return related words
				"true",				//  fetch the canonical version of this word (Cat => cat)
				"false"				//	return XML mark-up in response
			);

			for(Definition def : definitions) {
				System.out.print(def);
			}
		}
		catch (ApiException e) {

		}
	}	
}

This project was built with the following minimum requirements:

  • Maven 3.0
  • Java JDK 6