Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aiyu-ayaan/dictionary-ktor-server
Dictionary KMP is a Kotlin Multiplatform project that leverages Ktor Server to provide word definitions via a simple API. It fetches word meanings from an external dictionary API and handles requests efficiently with built-in timeout configurations.
https://github.com/aiyu-ayaan/dictionary-ktor-server
kotlin ktor-server
Last synced: about 2 months ago
JSON representation
Dictionary KMP is a Kotlin Multiplatform project that leverages Ktor Server to provide word definitions via a simple API. It fetches word meanings from an external dictionary API and handles requests efficiently with built-in timeout configurations.
- Host: GitHub
- URL: https://github.com/aiyu-ayaan/dictionary-ktor-server
- Owner: aiyu-ayaan
- License: mit
- Created: 2024-09-12T16:46:25.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-09-12T17:34:50.000Z (3 months ago)
- Last Synced: 2024-10-31T09:12:42.034Z (about 2 months ago)
- Topics: kotlin, ktor-server
- Language: Kotlin
- Homepage:
- Size: 66.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
README
# Dictionary-Ktor-Server
A simple Dictionary API using Ktor Server and Kotlin Multiplatform Project (KMP). This project fetches word definitions
from an external dictionary API.## Features
- **Ktor Server** for handling requests.
- **HTTP Client** to fetch word definitions from a third-party API.
- **Timeouts** configured to handle network delays.## Prerequisites
- [Kotlin](https://kotlinlang.org/) installed on your machine.
- [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) with KMP support.
- [Ktor](https://ktor.io/) for creating the server.## Getting Started
### Clone the Repository
```bash
git clone https://github.com/aiyu-ayaan/Dictionary-Ktor-Server
cd Dictionary-Ktor-Server
```### Setting Up the Ktor Server
1. Open the project in IntelliJ IDEA.
### Running the Application
1. Use the following command to run your Ktor server:
```bash
./gradlew run
```2. The server will be running on `http://localhost:9090/`.
### API Endpoints
#### Get Welcome Message
```http
GET /
```**Response:**
```json
{
"message": "Welcome to Dictionary API"
}
```#### Get Word Definition
```http
GET /word/{word}
```**Example Request:**
```http
GET /word/example
```**Response:**
Returns the JSON response from [Dictionary API](https://dictionaryapi.dev/).
```json
[
{
"word": "example",
"phonetic": "/əɡˈzæmpl̩/",
"phonetics": [
{
"text": "/əɡˈzæmpl̩/",
"audio": ""
},
{
"text": "/ɘɡˈzɐːmpɯ/",
"audio": ""
},
{
"text": "/ɪɡˈzɑːmpl̩/",
"audio": ""
},
{
"text": "/əɡˈzæmpl̩/",
"audio": "https://api.dictionaryapi.dev/media/pronunciations/en/example-us.mp3",
"sourceUrl": "https://commons.wikimedia.org/w/index.php?curid=267013"
}
],
"meanings": [
{
"partOfSpeech": "noun",
"definitions": [
{
"definition": "Something that is representative of all such things in a group.",
"synonyms": [],
"antonyms": []
},
{
"definition": "Something that serves to illustrate or explain a rule.",
"synonyms": [],
"antonyms": []
},
{
"definition": "Something that serves as a pattern of behaviour to be imitated (a good example) or not to be imitated (a bad example).",
"synonyms": [],
"antonyms": []
},
{
"definition": "A person punished as a warning to others.",
"synonyms": [],
"antonyms": []
},
{
"definition": "A parallel or closely similar case, especially when serving as a precedent or model.",
"synonyms": [],
"antonyms": []
},
{
"definition": "An instance (as a problem to be solved) serving to illustrate the rule or precept or to act as an exercise in the application of the rule.",
"synonyms": [],
"antonyms": []
}
],
"synonyms": [],
"antonyms": []
},
{
"partOfSpeech": "verb",
"definitions": [
{
"definition": "To be illustrated or exemplified (by).",
"synonyms": [],
"antonyms": []
}
],
"synonyms": [],
"antonyms": []
}
],
"license": {
"name": "CC BY-SA 3.0",
"url": "https://creativecommons.org/licenses/by-sa/3.0"
},
"sourceUrls": [
"https://en.wiktionary.org/wiki/example"
]
}
]
```### Error Handling
If an error occurs (e.g., invalid word or network issue), you'll get the following response:
```json
{
"error": "An error occurred"
}
```### Configuration
You can configure the timeouts in the `configureRouting` function:
```kotlin
install(HttpTimeout) {
requestTimeoutMillis = 30000 // 30 seconds
connectTimeoutMillis = 30000 // 30 seconds
}
```### Project Structure
- `Application.kt`: Contains the routing logic and API integration.
- `build.gradle.kts`: The Gradle configuration file.### Dictionary API
This project uses the [Dictionary API](https://dictionaryapi.dev/) to fetch word meanings.
## License
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.
## GitHub
[Dictionary KMP GitHub Repo](https://github.com/aiyu-ayaan/Dictionary-KMP)