Skip to content

Qames19/wordcount-server-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Wordcount Server

A simple asynchronous Rust web server that counts words from books stored in Redis.

Built using:

Features

  • Exposes a JSON API to retrieve the top words from a specified book.
  • Asynchronous Redis connection for fast data access.
  • Designed for easy extension (e.g., supporting .epub uploads).

API Endpoints

GET /api/top-words

Returns the top N most frequent words for a book.

Example:

curl http://localhost:3000/api/top-words

Response:

[
  {"word": "the", "count": 42},
  {"word": "and", "count": 37},
  {"word": "pride", "count": 20},
  {"word": "prejudice", "count": 18},
  {"word": "elizabeth", "count": 15}
]

GET /api/books

Lists all available book titles currently stored in Redis.

Example:

curl "http://localhost:3000/api/books"

Response:

[
  "pride-and-prejudice",
  "moby-dick",
  "war-and-peace"
]

POST /api/upload

Uploads a new book (plain text .txt only for now).

Form Fields:

  • title (text): Title of the book.
  • file (file): Plain text file containing the book content.

Example using curl:

curl -F "title=my-new-book" -F "file=@/path/to/book.txt" http://localhost:3000/api/upload

Response:

Book uploaded successfully

or

Failed to save book

Running Locally

  1. Clone the repository:
git clone https://github.com/your-username/my-wordcount-server.git  
cd wordcount-server-rust 
  1. Set up your environment:
cp .env.example .env
# Edit .env to match your Redis server details
  1. Run the server:
cargo run
  1. Access the API at:
    a. http://localhost:3000/api/top-words

Future Work

  • Allow dynamic book selection via query parameters.
  • Accept .epub uploads to extract and process book text automatically.
  • Improve outputs (Include extra visualizations).
  • Update UI/UX to be more enjoyable/visually appealing.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published