-
JSONP with the Wordnik API
Posted Jul 26, 2011
The Wordnik API supports JSONP syntax, meaning you can specify a function in any request and the Wordnik API will pad the response in your method name. This makes it easy to pass the response of any Wordnik API call back to your javascript-based code for asynchronous execution.
To use the JSONP feature, simply add a query param to any request:
callback={your_function_name}
For example:
http://api.wordnik.com/v4/word.json/cat/definitions?limit=1&callback=alert
Will produce the following response:
alert( [ { word: "cat" text: "A small carnivorous mammal ..." score: 0 partOfSpeech: "noun" sourceDictionary: "ahd-legacy" sequence: "0" } ] ) -
Using our Batch API syntax
Posted May 31, 2011
You can reduce your network calls by using our batch request mechanism. Batching is restricted to a single resource with the GET method but allows for variable query params and HTTP response codes. All calls in a request will be counted against the API access limiter.
A batch request is created by passing the
multiquery param and specifying resources and params with a positional suffix. Each batch item must designate a single resource, query params are optional.For example, to fetch multiple resources for the word
Cat, you can construct a request URI as follows:Call the definitions resource
resource.1=definitions
restrict to 2 definitions
limit.1=2
use the canonical form of the word
useCanonical.1=true
call the examples resource
resource.2=examples
get just one example
limit.2=1
use the canonical form of the word
useCanonical.2=true
get related items
resource.3=related
fetch synonyms
type.3=synonym
fetch 5 synonyms
limit.3=5
This is constructed into the following (sort of long) query string:
http://api.wordnik.com/v4/word.json/Cat?multi&resource.1=definitions&useCanonical.1&limit.1=2&resource.2=examples&limit.2=1&useCanonical.2=true&resource.3=related&type.3=synonym&limit.3=5&useCanonical.3=true
and gives a response as such:
{ responseItems: [ { responseName: "definitions" responsePosition: 1 responseContent: [ { id: 3117123 text: "Any animal belonging to the..." … } {...} } { responseName: "examples" responsePosition: 2 responseContent: [ { scoreId: 3305513809 year: 1992 provider: { name: "wordnik" id: 711 } display: "That mountain cat is a..." word: "cat" title: "Timegod's World" rating: 755.66016 exampleId: 281222695 documentId: 22330027 } ] } { responseName: "related" responsePosition: 3 responseContent: [ { words: [ "Angora" "chap" "qualifier" "kitling" "Maltese" ] relType: "synonym" } ] } ] }If you attempt to access an invalid resource or experience other non-200 HTTP responses, you will see a response message in the batch response:
... responseName: "nadanada" responsePosition: 3 responseContent: { message: "invalid resource" type: "error" } } -
Transition Guide to the v4 Wordnik API
Posted Mar 1, 2011
The v3 API will be maintained and supported until June 1st, 2011. After that, all requests to
api.wordnik.com/apiwill automatically be routed to the v4 API. After September 1st, 2011, the v3 path will be disabled.We will strive to maintain consistency between the v3 and v4 APIs. Bugs will be addressed in both versions when possible and new features will be added only to the v4 API. Furthermore, data in some features may stop seeing updates. Again, we will avoid this but it is inevitable that at some point, differences may arise such that we can only support the current production API.
We're here to help with your migration. Check out our documentation page for an interactive API shell that shows raw XML and JSON responses from our API which can make troubleshooting your client much simpler. In addition there's usually someone available to help out just about any time of the day. We only use real humans for answering support questions!
Here is a comprehensive list of changes between v3 and v4 of the Wordnik API.
Word Resource
The word resource has both request parameter and response changes which help make the API interactions more standard.
/word.{format}/{word}
Request Differences
useLiteralhas been removed and replaced withuseCanonical. The features are roughly the opposite of each other--if you passedliteral=true, you should passuseCanonical=falseuseSuggesthas been renamedincludeSuggestions
Response Differences
- The response object is now called
wordObject - The
idfield has been removed - The word itself has been renamed to
wordfromwordstring
/word.{format}/{word}/examples
Request Changes
showDuplicateshas been renamedincludeDuplicatessourcehas been renamedcontentProvider
Response changes
- the
wordstringattribute in each example has been renamedword displayhas been renamedtextscoreIdhas been removed
/word.{format}/{word}/definitions
Request changes
showRelatedhas been renamedincludeRelatedtagshas been renamedincludeTags
Response changes
headwordhas been renamedword- The
definitionsobject no longer contain theidattribute
/word.{format}/{word}/frequency
Request changes
startAthas been renamedstartYearendAthas been renamedendYear
Response changes
wordIdis no longer returned- The input
wordis now returned
/word.{format}/{word}/related
Request changes
- none
Response changes
- the
wordstringsresponse array has been renamedwords relTypehas been renamedrelationshipType
/word.{format}/{word}/pronunciations
Request changes
typehas been renamedtypeFormat
Response changes
- none
Words Resource
/words.{format}/randomWord
Request changes
lengthhas been removed. You can now setminLengthandmaxLength- There are a number of new parameters available in this API, please see the docs for a full list.
Response changes
- The
wordstringin the response has been renamedword
/words.{format}/randomWords
Request changes
- None
Response changes
- The
wordstringin the response has been renamedword
WordLists Resource
/wordList.{format}/{wordListId}/words
Request changes
- The format of data used in the POST (add words) methods has changed.
wordstringhas been replaced withword:
JSON:
[{"word":"cat"},{"word":"dog"}]XML:
<words> <word>cat</word> <word>dog</word> </words>/wordList.{format}/{wordListId}/deleteWords
Request changes
- As above, the method body attribute names have been changed from
wordstringtoword
Suggest Resource
We implemented the suggest resource to function as an autocomplete for word lookups. This has worked well but we have had a number of requests for more features, including selecting parts of speech, different ways to sort, wildcards, etc. To accommodate these requests, plus to add other functionality, this resource has been deprecated in favor of a word search API.
Old resource:
/suggest.{format}/{wordFragment}New resource:
/words.{format}/search/{wordFragment}Behavioral changes
- The word search method is now case sensitive. You can toggle this mode by passing
caseSensitive=falsein the request
Request changes
- The
wordFragmentsupports wildcards using an extended glob syntax. You can use@as a single-character vowel wildcard, and#as a single-character consonant wildcard. - A number of filters can be applied to the input; see the docs for a full list.
Response changes
matcheshas been renamed tototalResultsmorehas been removedsearchTermelement removed. The search term is always the first element in the response array, unless passingskip> 0matchhas been renamedsearchResults
Word of the Day
The functionality in the
wordoftheday.{format}resource has been moved to thewordsresource.Old resource:
/wordoftheday.{format}/New resource:
/words.{format}/wordOfTheDayBehavioral differences
- The
definitionsresponse now contains thesourceDictionaryand optionally thepartOfSpeechfor the definition - The
examplesresponse now contains both URLs and titles. - There is a
contentProviderfield, currently this is always an object identifyingwordnik
-
Help Methods via API
Posted Feb 10, 2011
Our new developer site has a REST API interface which calls our own API. If you're not the flashy, graphics types (you know who you are), you can now introspect our API by calling the endpoints directly:
- http://api.wordnik.com/v4/word.json
- http://api.wordnik.com/v4/word.xml
- http://api.wordnik.com/v4/words.json
- http://api.wordnik.com/v4/words.xml
- and so on...
This mechanism offers a lot of options, plus it gives us a chance to eat our own dogfood. APIs everywhere. We'll soon offer the model schemas by the same mechanism, and will post here once that's available.
JSON/XML/HTML? Now you have your choice!
-
Audio Pronunciations are Available via API
Posted Feb 10, 2011
Hi everyone,
We're happy to announce that we are now delivering audio pronunciations over our API. You can see the request info on the /docs page.
You request audio metadata via API and receive a time-expiring download URL. Currently the audio files are limited to MP3 pronunciations from the American Heritage Dictionary. We'll be offering the excellent Macmillan audio files shortly, as well as those created by users.
Feedback welcome!