A RESTful API built with Express.js to create, analyze, filter, retrieve, and delete strings. This API provides detailed properties for strings, including length, palindrome status, unique characters, word count, and SHA-256 hash. It also supports filtering strings using query parameters or natural language queries.
- Clone the repository:
git clone <repository_url>
cd <repository_folder>- Install dependencies:
npm install- Start the server:
npm startBy default, the server runs on http://localhost:3000.
Send HTTP requests to the API using tools like Postman, cURL, or any HTTP client. The API supports JSON payloads for creating strings and query parameters for filtering.
POST /strings
Request Body:
{
"value": "string to analyze"
}Responses:
201 Created– Returns the created string with analysis properties.400 Bad Request– Missing or invalidvalue.409 Conflict– String already exists.422 Unprocessable Entity–valueis not a string.
GET /strings
Query Parameters (optional):
is_palindrome(true/false)min_length(number)max_length(number)word_count(number)contains_character(string)
Response:
200 OK– Returns an array of strings matching filters.400 Bad Request– Invalid query parameter values.
GET /strings/filter-by-natural-language?query=<query_string>
Response:
200 OK– Returns filtered strings based on natural language query.400 Bad Request– Unable to parse query.422 Unprocessable Entity– Conflicting filters in query.
Example Queries:
"palindromic string longer than 5 words""string containing the first vowel shorter than 10 characters"
GET /strings/:value
Response:
200 OK– Returns the string object.404 Not Found– String does not exist.
DELETE /strings/:string_value
Response:
204 No Content– Successfully deleted.404 Not Found– String does not exist.
Each string object has the following structure:
{
"id": "sha256_hash",
"value": "string value",
"properties": {
"length": 17,
"is_palindrome": false,
"unique_characters": 12,
"word_count": 3,
"sha256_hash": "sha256_hash",
"character_frequency_map": {
"s": 1,
"t": 2
}
},
"created_at": "ISO8601 timestamp"
}curl -X POST http://localhost:3000/strings \
-H "Content-Type: application/json" \
-d '{"value":"never odd or even"}'curl http://localhost:3000/stringscurl "http://localhost:3000/strings?is_palindrome=true&min_length=5"curl "http://localhost:3000/strings/filter-by-natural-language?query=palindromic string longer than 5 characters"curl http://localhost:3000/strings/never%20odd%20or%20evencurl -X DELETE http://localhost:3000/strings/never%20odd%20or%20even