Skip to content
Open

Main #242

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
node_modules
node_modules
*.yml
*.sh
*.json
DOCKER.md
Dockerfile
.dockerignore
PR_MESSAGE.md
89 changes: 39 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@

There was no free Dictionary API on the web when I wanted one for my friend, so I created one.

## Data Source & License

This API uses [Wiktionary](https://en.wiktionary.org/) as its data source via the Wiktionary REST API. Wiktionary is a free, collaboratively edited multilingual dictionary.

### Attribution

Dictionary definitions provided by this API are sourced from [Wiktionary](https://en.wiktionary.org/), a project of the [Wikimedia Foundation](https://wikimediafoundation.org/).

The content from Wiktionary is available under the [Creative Commons Attribution-ShareAlike 4.0 International License (CC-BY-SA 4.0)](https://creativecommons.org/licenses/by-sa/4.0/).

**If you use this API, you must:**
- Provide attribution to Wiktionary as the source of the definitions
- Include a link to the CC-BY-SA 4.0 license
- If you modify the content, you must distribute your contributions under the same license

For individual word entries, the original contributors can be found in the page history at `https://en.wiktionary.org/wiki/<word>`.

## Important Note
The API usage has been ramping up rapidly, making it difficult for me to keep the server running due to increased AWS costs.

Your support directly helps the development of Dictionary API and keeps the server running.

<a href="https://www.buymeacoffee.com/meetdeveloper"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=meetdeveloper&button_colour=5F7FFF&font_colour=ffffff&font_family=Poppins&outline_colour=000000&coffee_colour=FFDD00"></a>
<a href="https://www.buymeacoffee.com/meetdeveloper"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&amp;emoji=&amp;slug=meetdeveloper&amp;button_colour=5F7FFF&amp;font_colour=ffffff&amp;font_family=Poppins&amp;outline_colour=000000&amp;coffee_colour=FFDD00"></a>

## Getting Started

Expand All @@ -25,48 +42,35 @@ As an example, to get definition of English word **hello** using _v2_, you can s
[
{
"word": "hello",
"phonetic": "həˈləʊ",
"phonetics": [
{
"text": "həˈləʊ",
"audio": "//ssl.gstatic.com/dictionary/static/sounds/20200429/hello--_gb_1.mp3"
},
{
"text": "hɛˈləʊ"
}
],
"origin": "early 19th century: variant of earlier hollo ; related to holla.",
"phonetics": [],
"meanings": [
{
"partOfSpeech": "exclamation",
"partOfSpeech": "interjection",
"definitions": [
{
"definition": "used as a greeting or to begin a phone conversation.",
"example": "hello there, Katie!",
"synonyms": [],
"antonyms": []
"definition": "A greeting (salutation) said when meeting someone or acknowledging someone's arrival or presence.",
"example": "Hello, everyone."
},
{
"definition": "A greeting used when answering the telephone.",
"example": "Hello? How may I help you?"
}
]
},
{
"partOfSpeech": "noun",
"definitions": [
{
"definition": "an utterance of ‘hello’; a greeting.",
"example": "she was getting polite nods and hellos from people",
"synonyms": [],
"antonyms": []
"definition": "\"Hello!\" or an equivalent greeting.",
"example": "They gave each other a quick hello when they met, and went back on their merry ways."
}
]
},
{
"partOfSpeech": "verb",
"definitions": [
{
"definition": "say or shout ‘hello’.",
"example": "I pressed the phone button and helloed",
"synonyms": [],
"antonyms": []
"definition": "To greet with \"hello\"."
}
]
}
Expand All @@ -75,47 +79,32 @@ As an example, to get definition of English word **hello** using _v2_, you can s
]
```

> **Note:** The API now uses Wiktionary as its data source. Response format remains compatible but some fields like `phonetic`, `origin`, `synonyms`, and `antonyms` may not always be present.

### Regarding V1 Version
The API earlier used to send response as shown below, but this structure of response was found out to be difficult to work with (you can take a look at these tickets [#32](https://github.com/meetDeveloper/freeDictionaryAPI/issues/32) and [#4](https://github.com/meetDeveloper/freeDictionaryAPI/issues/4)), based on feedback in these tickets I have updated the API to _v2_ version. But _v1_ version will always be supported for backward compatibility.

```json
[
{
"word": "hello",
"phonetic": "həˈləʊ",
"phonetics": [
{
"text": "həˈləʊ",
"audio": "//ssl.gstatic.com/dictionary/static/sounds/20200429/hello--_gb_1.mp3"
},
{
"text": "hɛˈləʊ"
}
],
"origin": "early 19th century: variant of earlier hollo ; related to holla.",
"phonetics": [],
"meaning": {
"exclamation": [
"interjection": [
{
"definition": "used as a greeting or to begin a phone conversation.",
"example": "hello there, Katie!",
"synonyms": [],
"antonyms": []
"definition": "A greeting (salutation) said when meeting someone.",
"example": "Hello, everyone."
}
],
"noun": [
{
"definition": "an utterance of ‘hello’; a greeting.",
"example": "she was getting polite nods and hellos from people",
"synonyms": [],
"antonyms": []
"definition": "\"Hello!\" or an equivalent greeting.",
"example": "They gave each other a quick hello."
}
],
"verb": [
{
"definition": "say or shout ‘hello’.",
"example": "I pressed the phone button and helloed",
"synonyms": [],
"antonyms": []
"definition": "To greet with \"hello\"."
}
]
}
Expand Down Expand Up @@ -147,7 +136,7 @@ This Dictionary API was initially created as an API that could be used by my fri

Kindly help me keep running and developing this API. Thanks a lot for using my API, it feels good when your creation help other create their own projects.

<a href="https://www.buymeacoffee.com/meetdeveloper"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=meetdeveloper&button_colour=5F7FFF&font_colour=ffffff&font_family=Poppins&outline_colour=000000&coffee_colour=FFDD00"></a>
<a href="https://www.buymeacoffee.com/meetdeveloper"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&amp;emoji=&amp;slug=meetdeveloper&amp;button_colour=5F7FFF&amp;font_colour=ffffff&amp;font_family=Poppins&amp;outline_colour=000000&amp;coffee_colour=FFDD00"></a>

## Related Projects

Expand Down
17 changes: 9 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ const { JSDOM } = require('jsdom'),
// GLOBALS
global._ = require('lodash');

function cleanText (text) {
function cleanText(text) {
if (!text) { return text; }

return parser
.parseFromString(text, "text/html")
.body.textContent;
const doc = parser.parseFromString(text, "text/html");
const elementsToRemove = doc.querySelectorAll("style, script");
elementsToRemove.forEach(el => el.remove());
return doc.body.textContent;
}


function handleError (error = {}) {
function handleError(error = {}) {
// Using duck typing to know if we explicitly threw this error
// If not then wrapping original error into UnexpectedError
if (!error.requestType) { error = new errors.UnexpectedError({ original_error: error }); }

const { requestType, title, message, resolution } = error;
status = REQUEST_TYPE_STATUS_CODE[requestType],
status = REQUEST_TYPE_STATUS_CODE[requestType],
body = JSON.stringify({
title,
message,
Expand Down Expand Up @@ -77,7 +78,7 @@ app.get('/api/:version/entries/:language/:word', async (req, res) => {
word = decodeURIComponent(word);

if (!word || !language || !version) {
return handleError.call(res, new errors.NoDefinitionsFound());
return handleError.call(res, new errors.NoDefinitionsFound());
}

// @todo: Find better error.
Expand All @@ -93,7 +94,7 @@ app.get('/api/:version/entries/:language/:word', async (req, res) => {
// @todo: Find better error.
if (!utils.isLanguageSupported(language)) { return handleError.call(res, new errors.NoDefinitionsFound()); }

word = word.trim().toLocaleLowerCase(language);
word = word.trim();

try {
let definitions = await dictionary.findDefinitions(word, language, { include }),
Expand Down
Loading