This project provides a simple API for translating text using the DeepL API. It is built using the Hono framework and TypeScript.
- Node.js (>= 18.x)
- npm or yarn
- DeepL API key
- Supported Languages
-
Clone the repository:
git clone https://github.com/your-username/deepl-hono-example.git cd deepl-hono-example -
Install dependencies:
npm install # or yarn install -
Create a .env file in the root directory and add your DeepL API key:
DEEPL_API_KEY=your_deepl_api_key
- Start the server:
npm run dev # or yarn dev - The server will start on port 3000 by default. You can access the API at
http://localhost:3000.
Translate text to a specified target language.
-
URL:
/translate -
Method:
POST -
Request Body:
texts(array of strings): The texts to be translated.targetLang(string): The target language code (e.g.,DEfor German,FRfor French).
-
Response:
200 OK: Returns the translated texts as an array of strings.400 Bad Request: Returns an error message if the input is invalid.500 Internal Server Error: Returns an error message if an error occurs during translation.
-
Example Request:
curl -X POST http://localhost:3000/translate \ -H "Content-Type: application/json" \ -d '{"texts": ["Hello, world!", "How are you?"], "targetLang": "DE"}' -
Example Response
["Hallo Welt!", "Wie geht es Ihnen?"]
This project is licensed under the MIT License. See the LICENSE file for details.