Skip to content

dctacademy/counter-api-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Name: Counter API Service

Description:

The Counter API Service is a lightweight, RESTful web service built on Node.js with the primary focus on managing and manipulating individual numeric counters. Through its endpoints, it offers clients the ability to create, read, update, and delete counters, and to adjust their numeric values based on predefined operations.

Key Features:

  1. List All Counters: Users can retrieve a complete list of all counters currently stored within the system.

  2. Unique Counter Identification: Every counter is uniquely identified using a timestamp-based ID, ensuring that each counter can be individually accessed and managed without conflicts.

  3. Value Manipulation: Users can easily increment, decrement, or reset specific counter values, allowing for real-time adjustment based on user interactions or events.

  4. JSON-based Persistent Storage: All counter data is securely and efficiently stored within a JSON file. This ensures data retention across system reboots and easy backup or transfer.

  5. Robust Error Handling: The API provides clear error messages, making it user-friendly and easy to debug. Whether a counter is not found or there's an issue with the operation type, users are kept informed.

Potential Use Cases:

  • Web-based Click Counters: Developers can implement this API to track and display the number of clicks on specific elements or pages.

  • Polling Systems: For systems that track user preferences or votes, each option could be represented by a counter.

  • Performance or Event Trackers: In scenarios where specific events (like downloads, uploads, or user logins) need to be tracked, each event can be a counter that increments with each occurrence.

APIs :

base url - http://localhost:3050

Method Endpoint Query Params Body Description Response
GET /api/counters - - Retrieves the list of all counters JSON array of counters
POST /api/counters - {} Creates a new counter with an autogenerated ID and initial value of 0 JSON object of the newly created counter
GET /api/counters/:id - - Retrieves a counter based on the provided ID JSON object of the specific counter
PUT /api/counters/:id type=increment, decrement, reset - Updates the counter's value based on the type query param Updated JSON object
DELETE /api/counters/:id - - Deletes a counter based on the provided ID JSON object of the deleted counter

Additional Notes:

  1. For the POST endpoint /api/counters, the body doesn't necessarily need to contain any specific information as it is mostly auto-generated. The ID is generated based on the current timestamp and the value is always set to 0.
  2. The PUT endpoint /api/counters/:id expects one of three values in the query parameter type: 'increment', 'decrement', or 'reset'. Depending on the value, it increments, decrements, or resets the counter value to 0.
  3. If a specific counter is not found for the GET, PUT, or DELETE operations, an empty JSON object {} is returned.

Installation:

  1. Clone the Repository: Use Git to clone the repository to your local machine:

    git clone https://github.com/dctacademy/counter-api-service.git
  2. Navigate to the Project Directory:

    cd counter-api-service
  3. Install Dependencies: Most Node.js projects use npm (Node Package Manager) or Yarn to manage dependencies. Check if there's a package.json file in the directory. If it exists, you can install the required packages using:

    npm install

    Or if there's a yarn.lock file, you might want to use:

    yarn
  4. Run the Service: Once everything is set up, you can typically start the service with:

    npm start

    Or, if the project uses Yarn:

    yarn start
  5. Access the Service: If everything is set up correctly and the service starts without any issues, you should be able to access the API through your browser or tools like Postman at the address specified

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors