Docs

Project Overview

This project leverages Redis for improved performance, utilizing Redis `SET`  and `ZADD`  commands to store and retrieve superhero data. By using Redis as an in-memory data store, we ensure that API response times are fast, with a return time of approximately  ~0.001s  for retrieving data. Redis provides the scalability needed to handle large volumes of requests efficiently.

Add Hero

POST /api/superheroes

Creates a new superhero entry with a name, superpower, and humility score.

Body Parameters:

{
  "name": "string",
  "superpower": "string",
  "humilityScore": "number"
}

Response:

{
  "message": "Superhero added successfully!",
  "superhero": {
    "id": 2,
    "name": "Batman",
    "superpower": "Intelligence",
    "humilityScore": 7
  }
}

Get All Heroes

GET /api/superheroes

Retrieves a list of all superheroes in the database, sorted by humility score.

Response:

{
  "superheroes": [
    {
      "id": 2,
      "name": "string",
      "superpower": "string",
      "humilityScore": 5
    }
  ]
}

Delete All Heroes

DELETE /api/superheroes

Deletes all superheroes from the database. Use with caution as this action is irreversible.

Response:

{
  "message": "All superheroes deleted successfully!"
}

Delete Hero by Body

DELETE /api/superheroes

Deletes a superhero entry from the database based on the provided request body containing superhero details.

Body Parameters:

{
  "id": "number",
  "name": "string",
  "superpower": "string",
  "humilityScore": "number"
}

Response:

{
  "message": "Superhero deleted successfully!"
}

Update Hero

PUT /api/superheroes

Updates an existing superhero entry with the provided name, superpower, and humility score.

Body Parameters:

{
  "id": "number",
  "name": "string",
  "superpower": "string",
  "humilityScore": "number"
}

Response:

{
  "message": "Superhero updated successfully!"
}

Initialize Superheroes

Function No parameters

This function initializes the superheroes by first checking if there are any existing heroes. If there are none, it adds some default heroes.

Response:

{
  "message": "Superheroes initialized successfully!"
}