A simple API implemented with Spring Boot for counting word frequencies in .txt files.
Returns the most common words found in the text file in an descending order array of JSON objects with the format of { word: word
, amount: amount
}, e.g. [{ word: "foo", amount: 2 }, { word: "bar", amount: 1}]
.
Has a simple barebones thymeleaf UI running on root address.
Must have Java runtime environment (JRE) installed in your computer (Java version 21 or above) to run the .jar file. If you want to pull and compile the code yourself then you will also need a Java Development Kit (JDK, Java version 21 or above). Also if you wish to run the automated tests you additionaly need to have git and maven installed.
Run app -instructions:
- Download the .jar file from the release page https://github.com/eerojala/WordCount-API/releases/tag/v1.0.2
- Place the .jar on location of your choosing and open a command line terminal.
- Open/navigate the command line whereever you placed the .jar
- Before running the application make sure that nothing is running on port 8080.
- Run the .jar file with
java -jar wordcount.api-1.0.2.jar
- The application should start and run in localhost:8080
- To count word frequencies directly with HTTP you can make HTTP POST requests to localhost:8080 with following information:
- Headers:
content-type multipart/form-data
- Body: two key/value pairs:
- key:
file
, value: the .txt file you wish to count the word frequencies for. Maximumfile
size is 50 MB. - key:
amount
, value: the amount of most common words fromfile
you wish for the API to return, i.e ifamount
= 10 then the API will return the 10 most common words fromfile
.amount
must be an integer between 1 and 2147483647.
- key:
- Headers:
Here is a guide on how you can send a file with Postman.
Below are screenshots of my Postman test request for reference:
Run tests -instructions:
- Clone this repository to your computer
- After cloning the repository navigate to the root folder of the repository using a command line
- Run the tests either with
mvn install
ormvm test