This is a microservice built on the Flask Python microframework. This microservice can be used to translate requested strings into Pig Latin, with the following specifications:
- Listens on port 80, accepts a string that contains at least one word, but potentially entire paragraphs.
- Convert the words to Pig Latin and return the results in the HTTP message body.
- Preserve all of the punctuation in the original string.
- Python 3.5
- Flask 0.12
- Requests 2.13.0
- Setuptools 20.10.1
A version of this microservice has been deployed on PythonAnywhere and you can test out this microservice in the console using the following command:
curl -d "Query anything you want\!" -i -X POST http://chriswt.pythonanywhere.com/api/translate
Install virtualenv
using pip if you do not already have it installed, pip install virtualenv
.
- Troubleshooting: If you have Anaconda installed, it is likely that your
virtualenv
PATH will not work for this particular implementation, this can be fixed by installingvirtualenv
with the built-in version of Python like so:/usr/local/bin/pip3.5 install virtualenv
To install all the dependencies required to run this microservice, use the command make install
.
To run the server, use the command sudo make launch
- Troubleshooting: because we are running on a protected port,
sudo
permissions must be used, either usesudo -s
to activatesudo
permissions for your current Terminal session, or execute the command usingsudo make launch
). This launches avirtualenv
with the dependencies installed previously.
To run the included unit tests, use the command make test
(note that this must be run after the server has been launched).
To shutdown the microservice, use the command make shutdown
. If you want to clean up all the build files and virtual environment files created, use the command make clean
.
The API can be interacted with at the 127.0.0.1/api/translate
endpoint. For example, we can cURL this resource with the following command:
curl -d "Query string here" -i -X POST 127.0.0.1/api/translate
The API accepts Content-Type: text/plain
or Content-Type: application/x-www-form-urlencoded
(it will also attempt to read from any json
stream) and returns Content-Type: text/plain
.
- Requirements generated using pipreqs
- Setup structure inspired by umermansoor's microservices
- Lorem Ipsum test paragraph generated from loripsum
- Testing framework: unittest