A RESTful API service that analyzes strings and stores their computed properties such as length, palindrome status, unique character count, word count, SHA-256 hash, and character frequency.
This project demonstrates API design, data validation, and string analysis using modern backend development practices.
This API receives strings, computes analytical properties, and persists them for future retrieval or filtering. It supports querying by computed metrics, natural language filters, and secure hash-based identification.
For each analyzed string, the API computes and stores the following:
| Property | Description |
|---|---|
| length | Number of characters in the string |
| is_palindrome | Boolean — true if the string reads the same backward (case-insensitive) |
| unique_characters | Total number of distinct characters |
| word_count | Number of words separated by whitespace |
| sha256_hash | Unique SHA-256 hash of the string |
| character_frequency_map | Object showing how often each character appears |
POST /strings
Analyzes and stores a new string.
{
"value": "string to analyze"
}{
"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": 3
}
},
"created_at": "2025-08-27T10:00:00Z"
}| Status | Description |
|---|---|
| 400 | Invalid body or missing "value" field |
| 409 | String already exists |
| 422 | "value" must be of type string |
GET /strings/{string_value}
Retrieve the analysis of a particular string.
{
"id": "sha256_hash_value",
"value": "requested string",
"properties": {
/* ... */
},
"created_at": "2025-08-27T10:00:00Z"
}404 String not found
GET /strings
Supports advanced filtering by computed properties.
GET /strings?is_palindrome=true&min_length=5&max_length=20&word_count=2&contains_character=a{
"data": [
{
"id": "hash1",
"value": "string1",
"properties": {
/* ... */
},
"created_at": "2025-08-27T10:00:00Z"
}
],
"count": 15,
"filters_applied": {
"is_palindrome": true,
"min_length": 5,
"max_length": 20,
"word_count": 2,
"contains_character": "a"
}
}| Parameter | Type | Description |
|---|---|---|
is_palindrome |
boolean | Filter by palindrome |
min_length |
integer | Minimum string length |
max_length |
integer | Maximum string length |
word_count |
integer | Exact word count |
contains_character |
string | Character that must appear |
400 Invalid query parameter types or values
Use human-like text queries to fetch matching strings.
GET /strings/filter-by-natural-language?query={text}| Query | Parsed Filters |
|---|---|
| "all single word palindromic strings" | { word_count: 1, is_palindrome: true } |
| "strings longer than 10 characters" | { min_length: 11 } |
| "strings containing the letter z" | { contains_character: "z" } |
| "palindromic strings that contain the first vowel" | { is_palindrome: true, contains_character: "a" } |
{
"data": [
/* matching strings */
],
"count": 3,
"interpreted_query": {
"original": "all single word palindromic strings",
"parsed_filters": {
"word_count": 1,
"is_palindrome": true
}
}
}| Status | Description |
|---|---|
| 400 | Query cannot be parsed |
| 422 | Parsed but filters are conflicting |
DELETE /strings/{string_value}
Removes a stored string and its analysis.
| Layer | Technology |
|---|---|
| Runtime | Node.js (v18+) |
| Framework | Express.js |
| Database | MongoDB / Mongoose |
| Security | Helmet, CORS, Express Rate Limit |
| Hashing | Node crypto module |
1. Clone Repository
git clone https://github.com/yourusername/string-analysis-api.git
cd string-analysis-api2. Install Dependencies
npm install3. Set Up Environment (.env)
PORT=5000
MONGO_URI=mongodb://localhost:27017/string_analysis_db4. Run Server
npm run dev5. Test the Endpoints
Use Postman, Insomnia, or cURL to interact with the API.
-
POST
/strings→ Analyze “racecar” -
GET
/strings/racecar→ Retrieve its analysis -
GET
/strings?is_palindrome=true→ Get all palindromic strings -
GET
/strings/filter-by-natural-language?query=strings longer than 10 characters -
DELETE
/strings/racecar→ Remove it
-
The SHA-256 hash acts as both a
unique IDandprimary key. -
Palindrome check ignores
caseandwhitespace. -
Character frequency map includes
spaces and punctuationfor completeness. -
Filtering supports
combined conditions. -
Natural language parsing may use basic keyword heuristics or a lightweight NLP library.
MIT License © 2025 — String Analysis API