This API is focused to translate text from English to Portuguese and from Portuguese to English using IBM Language Translator API. It is created using Typescript, NodeJs, ExpressJs and IBM Watson.
To setup this project for development, you need to install NodeJs.
node v12.14.1
After downloading NodeJs and cloning this project, you need to install all dependences. You can do it in two ways: Using NPM or Yarn packages.
Bash example using NPM:
npm install
Bash example using Yarn:
yarn
To run this project execute the follow command:
npm run dev:server
or
yarn dev:server
This API has two routes: /en-pt
and /pt-en
.
They are a POST Method, receive a JSON file with an object called "textToTranslate" and return a JSON file that contains "status", "statusText", "text".
Code example with Javascript using Axios to retrive data from API:
const axios = require("axios");
const url = "http://localhost:3333";
const textToTranslate = "source";
axios.post(`${url}/en-pt`, { textToTranslate }).then((response) => {
console.log(response.data);
});
API response:
{ status: 200, statusText: 'OK', text: 'fonte' }
Done in 2.43s.
- 200: This means that the text was translated and retrived as expected;
- 400: This means that the response body is invalid;
This project is under MIT license. See LICENSE for more details.