Flask based web service that suggests words starting with a given prefix. The words are obtained from a pre-configured corpus text file. This was implemented in the context of a python challenge.
DISCLAIMER: This web service can be unsuitable for big corpus, once it loads them entirely in memory.
This web service has the following dependencies:
Install them in your environment before running the server. You can use the requirements file at the root of the project:
pip install -r requirements.txt
The web service is configured using the following environment variables:
CORPUS_PATH: The path for the corpus text file. It should be a list of words, one by line.
Set the configurations variable before running the server:
export CORPUS_PATH=<corpus_file_path>
To run the server:
-
Set the flask application module, which is implemented in the
flaskrdirectory:export FLASK_APP=flaskr. -
Run the flask application:
flask run.
The web service provides the following end-point.
GET /suggestions
q- prefix for the suggestions be be obtained;limit- number of results to be obtained;offset- position of the first result to be obtained from all suggestions.
The response is a application/json with the following keys:
total- total number of suggestions for the given prefix;limit- number of results being presented;offset- position of the first result from all suggestions;next- URL for the next page of results.
Request:
GET /suggestions?q=F&limit=10&offset=10
Response:
{
limit : 10,
next: "suggestions?limit=10&offset=20",
offset: 10,
results: [
"FaceApp",
"FaceLock for apps",
"FaceLOOK for Facebook",
"Facetune",
"FaceSwap Face Swap Live",
"Fast Racing 3D",
"Fast Reboot",
"Fast Download Manager",
"Fast Followers",
"Fast Facebook Video Downloader",
],
total: 393
}All unit tests can be run using pytest from the project's root directory.
pytest