An API Builder API to translate text using AWS Translate
879
A text translation API example based on API Builder. Project can be found here on Github. The API leverages AWS Comprehend.
The API is an example of an API First API designed in Stoplight and Built in API Builder as described in the following blog post:
The API is shown below:
GET /translatetext?TargetLanguageCode=ja&Text=Hello'
and accepts the text to be translated and the target language code as query parameters, "Text" and "TargetLanguageCode". It automatically detects the source text language.
It returns the translated text:
{
"TranslatedText": "こんにちは",
"SourceLanguageCode": "en",
"TargetLanguageCode": "ja"
}
The API uses API Key authentication that is passed in a header with key apikey.
The container requires three env vars:
You can read about AWS credentials here.
You can run the container locally using the following commands:
docker run --name apib_translate -e API_KEY=<API KEY YOU PROVIDE> -e AWS_ACCESS_KEY_ID=<YOUR AWS ACCESS KEY> -e AWS_SECRET_ACCESS_KEY=<YOUR AWS SECRET> -p 8080:8080 --rm lbrenman/apib_translate
curl --request GET --url 'http://localhost:8080/api/translatetext?TargetLanguageCode=ja&Text=Hello' --header 'Content-Type: application/json' --header 'apiKey: <API KEY YOU PROVIDE>'
Response:
{
"TranslatedText": "こんにちは",
"SourceLanguageCode": "en",
"TargetLanguageCode": "ja"
}
Content type
Image
Digest
Size
79.6 MB
Last updated
over 4 years ago
docker pull lbrenman/apib_translate