Skip to content

toramanomer/key-counter

Repository files navigation

Key Counter

A simple server built with NestJS that tracks the frequency of input keys submitted via HTTP requests.

Endpoints

  1. POST /input
    • Description: Increments the count of the key if the key already exists, otherwise creates a new key with a count of 1. The key is case-sensitive and is trimmed before being stored.
    • Request Headers: Content-Type: text/plain. Otherwise, the server will respond with a 415 Unsupported Media Type error.
    • Request Body: Non-empty string containing the key to be stored. Throws a 400 Bad Request error if the body is empty.
    • Success Response: 204 No Content
  2. GET /query
    • Description: Retrieves the count of the key. The key is case-sensitive and is trimmed before being queried.
    • Query Parameters: key - Non-empty string containing the key to be queried. Throws a 400 Bad Request error if the key is not provided.
    • Success Response: 200 OK with the count of the key in the response body.

Installation

  1. Clone the repository:

    git clone [email protected]:toramanomer/key-counter.git
  2. Navigate to the project directory, and install the dependencies:

    cd key-counter && npm install
  3. Start the server in watch mode:

    npm run start:dev

Building Locally

After installing the dependencies, you can build the project with the following command:

npm run build && npm run start:prod

Building with Docker

  1. Build Script is provided to build the Docker image.
    chmod +x scripts/build.sh && scripts/build.sh
  2. Run Script is provided to run the Docker container.
    chmod +x scripts/run.sh && scripts/run.sh

Running End-to-End Tests

npm run test:e2e

Recommended Extensions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published