This project provides a simple API for translating English text to French using the free-translate library. The API is built with Express.js and includes a translation service and controller.
To use this API, follow the steps below:
-
Clone the repository:
git clone https://github.com/priyanshusingh305/api-assignment.git
-
Install dependencies:
cd translation-api npm install
-
Start the server:
npm start
The API will be accessible at http://localhost:5454.
-
Endpoint:
/translate/engtofr
-
Method: POST
-
Request Body:
{ "text": "Enter your English text here" }
-
Response:
-
Status Code: 201
-
Body:
{ "translation": "Your translated text in French" }
-
Status Code: 400 (Bad Request)
-
Body:
{ "error": "Text to translate is required" }
-
-
Status Code: 500 (Internal Server Error)
-
Body:
{ "error": "Failed to translate text" }
-
-
/services/translation.service.js
: Translation service containing the logic for English to French translation./controller/translate.controller.js
: Controller handling the translation request./routes/translate.route.js
: Express router defining the API endpoint and connecting it to the controller.app.js
: Main application file, setting up the Express app, defining routes, and starting the server.
- express: Web framework for Node.js.
- free-translate: Node.js wrapper for the Free Translate API.
Visit http://localhost:5454 to access the API and follow the provided endpoint documentation for translation.
Feel free to explore and modify the code to suit your needs!