Have you ever felt the need to look up the definition of a colloquially used slang word? The Urban Dictionary API can come to your rescue!
An easy-to-use dictionary feature in your application or website can greatly enhance the user experience for your prospective users. The feature would enable your users to look up the meaning of words and phrases. This would inherently empower your users to engage with your content in a more meaningful manner. However, building a dictionary from scratch is time-consuming and cumbersome. A convenient solution would be to simply integrate a dictionary service that allows access to its dictionary database through an API.
What is the Urban Dictionary API?
The Urban Dictionary API is a REST based API service for looking up definitions of words and phrases. It is a community-driven initiative that relies on crowd-sourced definitions of words and phrases in the English language. Although this API is unofficial, the service is popular primarily for its definitions of slang and other colloquially used words and phrases.
How does the Urban Dictionary API work?
The Urban Dictionary API takes the term to look up as the input and returns a list of crowd-sourced definitions and usage examples as the output. Each list item contains the definition, example usage in addition to the up-votes and down-votes the item received from the community. Thus instead of providing the user with a single definition for a word or a phrase, the user of the API is presented with a list of definitions and example usages with their corresponding votes.
Who is the Urban Dictionary API for exactly?
The Urban Dictionary API is intended to serve application developers and web developers and also startups and enterprises – who are looking to integrate an efficient and easy-to-use dictionary service in their application or website.
How to connect to the Urban Dictionary API Tutorial – Step by Step
The following is a step-by-step tutorial for connecting to the Urban Dictionary API.
Step 1: Sign Up on RapidAPI
A RapidAPI account is required to connect to the Urban Dictionary API. You can sign up for a RapidAPI account by navigating to the RapidAPI website and clicking on the Sign-Up button at the top right!
RapidAPI supports signing up using Google, Github, or Facebook.
Step 2: Connect and Test the Urban Dictionary API
You can connect and test the API connection by navigating to the Urban Dictionary API page on the RapidAPI website. The Urban Dictionary API is a free to use API.
To connect and test the API connection, please click on the “Test Endpoint” button. A successful connection would result in a “200 OK” response in the Results tab on this page.
Now that you have connected and tested the connection to the Urban Dictionary API, let’s learn more about its usage!
Endpoint of the Urban Dictionary API
The Urban Dictionary API has one endpoint – “define
” to facilitate lookup for words and phrases. The endpoint with the relevant information on its usage is as follows:
Define
This endpoint facilitates fetching of definitions and usage examples for provided “term
”string.
This endpoint requires one parameter:
- “
term
” – indicating the string whose definitions and usage examples are to be returned.
- “
The API response contains a list with each list item containing – “definition
”, “permalink
”, “example
”, “author
”, “word
”, “thumbs_up
”, “thumbs_down
” and a list of “sound_urls
” values for the corresponding input parameter – “term
” string.
How to use the Urban Dictionary API with Python?
The following code snippet depicts the request with the required parameters to the “define” endpoint of the Urban Dictionary API with Python. It uses the “requests” library to send a GET request to the endpoint with the parameter “term” specified in the “querystring” dictionary.
The “x-rapidapi-key
” value in the “headers” dictionary would need to be replaced with your actual key which can be obtained from the Urban Dictionary API’s page for the “get” endpoint in the Header Parameters section.
import requests url = "https://mashape-community-urban-dictionary.p.rapidapi.com/define" querystring = {"term":"wat"} headers = { 'x-rapidapi-key': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'x-rapidapi-host': "mashape-community-urban-dictionary.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
How to use the Urban Dictionary API with PHP?
The following code snippet depicts the request with the required parameters to the “define” endpoint of the Urban Dictionary API with PHP. It uses the “curl” function of PHP to send a GET request to the endpoint with the parameters specified in the “CURLOPT_URL”.
The “x-rapidapi-key
” value in the “CURLOPT_HTTPHEADER” object would need to be replaced with your actual key which can be obtained from the Urban Dictionary API’s page for the “define” endpoint in the Header Parameters section.
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=wat", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: mashape-community-urban-dictionary.p.rapidapi.com", "x-rapidapi-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
How to use the Urban Dictionary API with Ruby?
The following code snippet depicts the request with the required parameters to the “define” endpoint of the Urban Dictionary API with Ruby. The “x-rapidapi-key
” value in the “request” object would need to be replaced with your actual key which can be obtained from the Urban Dictionary API‘s page for the “define” endpoint in the Header Parameters section.
require 'uri' require 'net/http' require 'openssl' url = URI("https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=wat") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' request["x-rapidapi-host"] = 'mashape-community-urban-dictionary.p.rapidapi.com' response = http.request(request) puts response.read_body
How to use the Urban Dictionary API with JavaScript?
The following code snippet depicts the request with the required parameters to the “define” endpoint of the Urban Dictionary API with Javascript. It uses JQuery’s “ajax” function to send a GET request to the endpoint with the parameters specified in the “settings” object.
The “x-rapidapi-key
” value in the “headers” object would need to be replaced with your actual key which can be obtained from the Urban Dictionary API’s page for the “define” endpoint in the Header Parameters section.
const settings = { "async": true, "crossDomain": true, "url": "https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=wat", "method": "GET", "headers": { "x-rapidapi-key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "x-rapidapi-host": "mashape-community-urban-dictionary.p.rapidapi.com" } }; $.ajax(settings).done(function (response) { console.log(response); });
Alternatives to the Urban Dictionary API
A few alternatives APIs that provide dictionary lookup capabilities similar to the Urban Dictionary API are:
- Word Dictionary
- This API facilitates lookup for definitions, examples, references and associations.
- Lingua Robot
- This API enables users to get word definitions, usage examples, pronunciations, synonyms and antonyms or for text processing.
- XF English Dictionary
- This API facilitates looking up for definitions of English words and phrases plus usage examples, word forms, synonyms, antonyms, pronunciation data, and word frequencies
- Dictionary
- This API enables access to definitions, translations, synonyms, and audio pronunciations.
Benefits of the Urban Dictionary API
There are numerous dictionary API services available on the web that enable users to look up word definitions. However, the Urban Dictionary API sets itself apart in two significant aspects (1) Support for slang words and colloquial phrases and (2) a Community-driven user-contributed rating system. The community-driven approach of the Urban Dictionary influences both these aspects. Since the user community collectively contributes to the dictionary, more contemporary, slang, and colloquial phrases are continuously added to the dictionary database. Thus the dictionary is richer and more relevant to the current times. Moreover, the user-contributed rating system allows users to rate word definitions and usage examples using up-votes and down-votes. This further democratizes the relevance of word definitions. Thus an end-user is presented with a list of word definitions and their corresponding example usages in addition to their up-votes and down-votes. This empowers the end-user with a choice to select and use a particular word definition and example from the returned list of multiple definitions.
Summary
The Urban Dictionary API is a powerful tool for app and web developers, intended for seamless integration of a dictionary feature in an app or a website. The API thus enables its users to look up the definitions and example usages of words and phrases, including slang and colloquially used words.
Leave a Reply