Skip to content

Ehiz-js/string-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Analysis API

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.

Table of Contents

Installation

  1. Clone the repository:
git clone <repository_url>
cd <repository_folder>
  1. Install dependencies:
npm install
  1. Start the server:
npm start

By default, the server runs on http://localhost:3000.


Usage

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.


Endpoints

1. Create and Analyze String

POST /strings

Request Body:

{
	"value": "string to analyze"
}

Responses:

  • 201 Created – Returns the created string with analysis properties.
  • 400 Bad Request – Missing or invalid value.
  • 409 Conflict – String already exists.
  • 422 Unprocessable Entityvalue is not a string.

2. Get All Strings with Filtering

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.

3. Natural Language Filtering

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"

4. Get Specific String

GET /strings/:value

Response:

  • 200 OK – Returns the string object.
  • 404 Not Found – String does not exist.

5. Delete String

DELETE /strings/:string_value

Response:

  • 204 No Content – Successfully deleted.
  • 404 Not Found – String does not exist.

Data Structure

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"
}

Setup Example with cURL

Create a string

curl -X POST http://localhost:3000/strings \
-H "Content-Type: application/json" \
-d '{"value":"never odd or even"}'

Get all strings

curl http://localhost:3000/strings

Filter strings by query parameters

curl "http://localhost:3000/strings?is_palindrome=true&min_length=5"

Filter strings using natural language query

curl "http://localhost:3000/strings/filter-by-natural-language?query=palindromic string longer than 5 characters"

Get a specific string

curl http://localhost:3000/strings/never%20odd%20or%20even

Delete a string

curl -X DELETE http://localhost:3000/strings/never%20odd%20or%20even

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published