Skip to content

Programer-Ed/string_analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧙‍♂️ Backend Wizards — Stage 1: String Analyzer Service

This project implements a RESTful API that analyzes strings and computes various properties such as length, palindrome check, and SHA-256 hash.


✨ Overview

This API receives a string and returns a JSON object describing it. Example properties include:

  • length — Number of characters
  • is_palindrome — Whether it reads the same backward and forward (case-insensitive)
  • unique_characters — Count of distinct characters
  • word_count — Number of words separated by spaces
  • sha256_hash — Secure hash of the string
  • character_frequency_map — Count of each character’s occurrence

All analyzed strings are stored in memory (can be replaced with a database later).


⚙️ Tech Stack

Component Description
Language Python 3.10+
Framework Flask
Libraries Flask, hashlib, datetime, re, gunicorn
Hosting Railway.app

🚀 How to Run Locally

1️⃣ Clone the repository

git clone https://github.com/Programer-Ed/string_analyzer.git
cd string_analyzer

2️⃣ Create a virtual environment

python3 -m venv venv
source venv/bin/activate    # On macOS/Linux
venv\Scripts\activate       # On Windows

3️⃣ Install dependencies

pip install -r requirements.txt

If you don’t have a requirements.txt yet, create one with:

Flask
gunicorn

4️⃣ Run the app locally

python app.py

Then open your browser or Postman and visit:

http://127.0.0.1:5000

🌍 Deploying to Railway

🧩 1. Ensure these files exist in your repo:

  • app.py
  • requirements.txt
  • Procfile

📄 Procfile content:

web: gunicorn app:app

🚢 2. Steps to deploy:

  1. Go to https://railway.app/
  2. Click "New Project" → "Deploy from GitHub"
  3. Connect your repository
  4. Railway will auto-detect your Procfile and start the Flask app

✅ Once deployed, you’ll get a public URL like:

https://string-analyzer-production.up.railway.app/

🧪 API Endpoints

➕ Create / Analyze a String

POST /strings Body (JSON):

{ "value": "racecar" }

Response:

{
  "id": "f5c5...",
  "value": "racecar",
  "properties": {
    "length": 7,
    "is_palindrome": true,
    "unique_characters": 5,
    "word_count": 1,
    "sha256_hash": "f5c5...",
    "character_frequency_map": { "r": 2, "a": 2, "c": 2, "e": 1 }
  },
  "created_at": "2025-10-21T00:00:00Z"
}

🔍 Search & Filter Strings

GET /strings?q=car&is_palindrome=true&min_length=5

🧠 Natural Language Filter

GET /strings/filter-by-natural-language?query=strings longer than 5 and palindromes

❌ Delete String

DELETE /strings/<string_value>


⚙️ Environment Variables

No environment variables are needed for this project (yet). You can add one later, e.g. FLASK_ENV=production if desired.


🧩 Example Tests in Postman

1️⃣ Create a string → POST /strings 2️⃣ Get all strings → GET /strings 3️⃣ SearchGET /strings?q=go 4️⃣ Filter by NLPGET /strings/filter-by-natural-language?query=palindromes longer than 4 5️⃣ Delete a string → DELETE /strings/<string_value>

Releases

No releases published

Packages

No packages published