The String Analyzer API is a robust Node.js Express backend service designed to process and analyze textual data. It leverages Express.js for routing, crypto for SHA256 hashing, and compromise for natural language processing, offering advanced string analysis, storage, and retrieval functionalities.
- String Persistence: Stores strings along with their calculated properties in memory.
 - Comprehensive Analysis: Automatically calculates string length, palindrome status, unique character count, word count, and character frequency.
 - Secure Identification: Generates a unique SHA256 hash for each string to ensure integrity and serve as an identifier.
 - Flexible Retrieval: Supports fetching all stored strings or a specific string by its original value.
 - Advanced Filtering: Enables searching for strings based on multiple criteria like palindrome status, length, word count, or character presence via query parameters.
 - Natural Language Query: Filters strings using intuitive natural language sentences, powered by the 
compromiseNLP library. - String Deletion: Allows for removal of strings from the system.
 
| Technology | Description | 
|---|---|
| Node.js | JavaScript runtime for server-side execution. | 
| Express.js | Fast, unopinionated, minimalist web framework for Node.js. | 
| crypto | Node.js built-in module for cryptographic functionality (SHA256 hashing). | 
| dotenv | Zero-dependency module that loads environment variables from a .env file. | 
| compromise | A JavaScript natural language processing (NLP) library for parsing text. | 
| nodemon | Development utility that monitors for any changes in source and restarts. | 
To get this project up and running on your local machine, follow these steps:
- 
Clone the Repository:
git clone https://github.com/pemzyj/string-analyzer.git cd Stage\ 1
 - 
Install Dependencies: Navigate into the project directory and install the necessary npm packages.
npm install
 - 
Start the Development Server: To run the application in development mode with
nodemonfor automatic restarts:npm run dev
 - 
Start the Production Server: To run the application in production mode:
npm start
The API will be available at
http://0.0.0.0:[PORT](default is8000). 
The project uses environment variables managed by dotenv. Create a .env file in the root directory of the project with the following variable:
PORT: The port number on which the Express server will listen.PORT=8000
http://localhost:8000 (or your configured PORT)
Adds a new string to the system and calculates its properties.
Request:
{
  "value": "string"
}Response:
{
  "id": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
  "value": "madam",
  "properties": {
    "length": 5,
    "is_palindrome": true,
    "unique_characters": 3,
    "word_count": 1,
    "sha256_hash": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
    "character_frequency_map": {
      "m": 2,
      "a": 2,
      "d": 1
    }
  },
  "created_at": "2023-10-27T10:00:00.000Z"
}Errors:
400 Bad Request: String is missing.{ "error": "String is missing" }422 Unprocessable Entity: Value provided is not a string.{ "error": "123 must be a string" }409 Conflict: String already exists in the system.{ "error": "String already exists in system" }
Retrieves all stored strings or filters them based on query parameters.
Request: Optional query parameters:
is_palindrome:trueorfalsemin_length: Integermax_length: Integerword_count: Integercontains_character: Single character
Example (no query parameters): GET /strings
Example (with query parameters): GET /strings?is_palindrome=true&min_length=5&contains_character=a
Response:
{
  "data": [
    {
      "id": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
      "value": "madam",
      "properties": {
        "length": 5,
        "is_palindrome": true,
        "unique_characters": 3,
        "word_count": 1,
        "sha256_hash": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
        "character_frequency_map": {
          "m": 2, "a": 2, "d": 1
        }
      },
      "created_at": "2023-10-27T10:00:00.000Z"
    },
    {
      "id": "1d80327e52dd040b07b8b2e59e6c99c3cf0c17ae5107e38ee129188a87b1897d",
      "value": "hello world",
      "properties": {
        "length": 11,
        "is_palindrome": false,
        "unique_characters": 8,
        "word_count": 2,
        "sha256_hash": "1d80327e52dd040b07b8b2e59e6c99c3cf0c17ae5107e38ee129188a87b1897d",
        "character_frequency_map": {
          "h": 1, "e": 1, "l": 3, "o": 2, "w": 1, "r": 1, "d": 1
        }
      },
      "created_at": "2023-10-27T10:05:00.000Z"
    }
  ],
  "count": 2,
  "filters_applied": {
    "min_length": 5,
    "contains_character": "a"
  }
}Errors:
400 Bad Request: Invalid query parameter values or types.{ "error": "Invalid query parameter values or types" }
Filters strings based on a natural language query.
Request: Query parameter:
query: Natural language string (e.g., "strings that are palindromes and have two words", "strings longer than 5 letters")
Example: GET /strings/filter-by-natural-language?query=strings that are palindromes
Response:
{
  "data": [
    {
      "id": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
      "value": "madam",
      "properties": {
        "length": 5,
        "is_palindrome": true,
        "unique_characters": 3,
        "word_count": 1,
        "sha256_hash": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
        "character_frequency_map": {
          "m": 2, "a": 2, "d": 1
        }
      },
      "created_at": "2023-10-27T10:00:00.000Z"
    }
  ],
  "count": 1,
  "interpreted_query": {
    "original": "strings that are palindromes",
    "parsed_filters": {
      "is_palindrome": true
    }
  }
}Errors:
400 Bad Request: Missing natural language query.{ "error": "Missing natural language query" }400 Bad Request: Unable to parse natural language query.{ "error": "Unable to parse natural language query" }422 Unprocessable Entity: Query parsed but resulted in conflicting filters.{ "error": "Query parsed but resulted in conflicting filters" }
Retrieves a single string by its original value's SHA256 hash. The :string_value in the path should be the original string itself, which the API then hashes to find the stored entry.
Request:
Path parameter: string_value (e.g., madam)
Example: GET /strings/madam
Response:
{
  "id": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
  "value": "madam",
  "properties": {
    "length": 5,
    "is_palindrome": true,
    "unique_characters": 3,
    "word_count": 1,
    "sha256_hash": "e4e941740b2e84d43e26487e8e50b925b44d34c114e9f7831d36d41870183b10",
    "character_frequency_map": {
      "m": 2, "a": 2, "d": 1
    }
  },
  "created_at": "2023-10-27T10:00:00.000Z"
}Errors:
404 Not Found: String doesn't exist in system.{ "error": "String doesn't exist in system" }
Deletes a string from the system by its original value's SHA256 hash. The :string_value in the path should be the original string itself.
Request:
Path parameter: string_value (e.g., madam)
Example: DELETE /strings/madam
Response:
204 No Content (Successful deletion, no response body)
Errors:
404 Not Found: String doesn't exist in system.{ "error": "String doesn't exist in system" }
Once the server is running, you can interact with the API using tools like curl, Postman, Insomnia, or any HTTP client.
- 
Add a String:
curl -X POST -H "Content-Type: application/json" -d '{"value": "hello world"}' http://localhost:8000/strings
 - 
Retrieve All Strings:
curl http://localhost:8000/strings
 - 
Filter Strings by Properties:
curl 'http://localhost:8000/strings?is_palindrome=true&min_length=3' - 
Filter Strings with Natural Language:
curl 'http://localhost:8000/strings/filter-by-natural-language?query=show me words with one word' - 
Retrieve a Specific String:
curl http://localhost:8000/strings/madam
 - 
Delete a String:
curl -X DELETE http://localhost:8000/strings/madam
 
We welcome contributions to enhance the String Analyzer API! If you have ideas for new features, improvements, or bug fixes, please follow these guidelines:
- Fork the Repository: Start by forking the project to your GitHub account.
 - Create a New Branch: Create a descriptive branch for your feature or bug fix (e.g., 
feature/add-new-analysis,fix/palindrome-logic). - Write Clear Commits: Ensure your commit messages are concise and informative.
 - Submit a Pull Request: Open a pull request against the 
mainbranch of this repository. Clearly describe your changes and the problem they solve. 
This project is licensed under the ISC License.
Developed by Olamide.
- LinkedIn: [Your LinkedIn Profile]
 - Twitter: [Your Twitter Handle]