Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

String Analyzer API

A RESTful API service that analyzes strings and stores their computed properties including length, palindrome detection, unique characters, word count, SHA-256 hash, and character frequency mapping.

🚀 Live Demo

API Base URL: https://stringanalyzer-production-0bbb.up.railway.app

📋 Features

  • ✅ Analyze and store strings with computed properties
  • ✅ Retrieve stored string analyses
  • ✅ Filter strings by multiple criteria
  • ✅ Natural language query support
  • ✅ SQLite database for persistence
  • ✅ Complete error handling
  • ✅ RESTful API design

🛠️ Tech Stack

  • Language: Python 3.13
  • Framework: Flask
  • Database: SQLite
  • Deployment: Railway

📦 Installation & Setup

Prerequisites

  • Python 3.11 or higher
  • pip (Python package manager)

Local Development

  1. Clone the repository

    git clone https://github.com/arithenshaw/String_Analyzer.git
    cd string-analyzer-api
  2. Create a virtual environment

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Run the application

    python app.py

    The API will be available at http://localhost:5000

🔗 API Endpoints

1. Create/Analyze String

POST /strings

Request Body:

{
  "value": "string to analyze"
}

Success Response (201):

{
  "id": "sha256_hash_value",
  "value": "string to analyze",
  "properties": {
    "length": 17,
    "is_palindrome": false,
    "unique_characters": 12,
    "word_count": 3,
    "sha256_hash": "abc123...",
    "character_frequency_map": {
      "s": 2,
      "t": 2,
      ...
    }
  },
  "created_at": "2025-08-27T10:00:00Z"
}

Error Responses:

  • 400 - Invalid request body or missing "value" field
  • 409 - String already exists in the system
  • 422 - Invalid data type for "value" (must be string)

2. Get Specific String

GET /strings/{string_value}

Success Response (200):

{
  "id": "sha256_hash_value",
  "value": "requested string",
  "properties": { ... },
  "created_at": "2025-08-27T10:00:00Z"
}

Error Response:

  • 404 - String does not exist in the system

3. Get All Strings with Filtering

GET /strings

Query Parameters:

  • is_palindrome (boolean): Filter palindromes
  • min_length (integer): Minimum string length
  • max_length (integer): Maximum string length
  • word_count (integer): Exact word count
  • contains_character (string): Must contain character

Example:

GET /strings?is_palindrome=true&min_length=5&max_length=20

Success Response (200):

{
  "data": [ ... ],
  "count": 15,
  "filters_applied": {
    "is_palindrome": true,
    "min_length": 5
  }
}

4. Natural Language Filtering

GET /strings/filter-by-natural-language?query={natural_language_query}

Examples:

  • ?query=all single word palindromic strings
  • ?query=strings longer than 10 characters
  • ?query=strings containing the letter z

Success Response (200):

{
  "data": [ ... ],
  "count": 3,
  "interpreted_query": {
    "original": "all single word palindromic strings",
    "parsed_filters": {
      "word_count": 1,
      "is_palindrome": true
    }
  }
}

Error Responses:

  • 400 - Unable to parse natural language query
  • 422 - Query parsed but resulted in conflicting filters

5. Delete String

DELETE /strings/{string_value}

Success Response:

  • 204 - No Content (empty response body)

Error Response:

  • 404 - String does not exist in the system

🧪 Testing

Run the test suite:

python tests/test_api.py

Manual Testing with cURL:

Create a string:

curl -X POST http://localhost:5000/strings \
  -H "Content-Type: application/json" \
  -d '{"value": "racecar"}'

Get all palindromes:

curl "http://localhost:5000/strings?is_palindrome=true"

Natural language query:

curl "http://localhost:5000/strings/filter-by-natural-language?query=palindromic%20strings"

🚢 Deployment

Deploy to Railway:

stringanalyzer-production-0bbb.up.railway.app

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages