Flask based HTTP service to consume text and return the number of words.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Linux system: Ubuntu 16.04 (Xenial) or later
python 3.5.2
pip
Clone source code from git repo
$ git clone https://github.com/fernandorovai/WordCounter.git
Setup and activate virtual environment
$ virtualenv WordCounter -p python3
$ cd WordCounter
$ source ./bin/activate
Install python dependencies via pip
$ pip install -r requirements.txt # python libraries
$ python -m spacy download en # download english model
Start the webserver
$ cd WordCounter
$ python init.py
# to run webserver in debug mode, set app.debug var in init.py
app.debug = True
Expected output
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Receive the number of words based on user's input text. Server is expecting to receive a POST message with a determined field.
requestUrl : http://localhost:5000/processText
method : POST
dataStructure : bagOfText:"This is an example of text"
Expected output:
outputStructure : {
"errorMsg": null,
"wordCounter": "6"
}
Receive the number of words based on form user's input text.
1. Go to http://localhost:5000
2. Fill the form with text
3. Press submit button to receive the number of words
The script webServerTestCase.py runs the following tests
- test_invalid_request : send a post request without form content
- test_complete_post : send a post request with complete form content
- test_empty_post : send a post request with empty value
- test_multiple_requests : send multi-thread post requests
To start the test case:
$ cd WordCounter
$ python webServerTestCase
Expected output:
Ran 4 tests in 500ms
OK
Flask’s built-in server is not suitable for production. Consider deploying the application to a WSGI Server.
For more information, check Flask Documentation
- Fernando Rodrigues Jr - Initial work - Fernando