Titans

Titans

Welcome to the documentation for the Greek Myth API endpoint. This endpoint offers comprehensive data on various heroes from Greek mythology, allowing you to seamlessly integrate rich content into your applications.

Endpoint Overview

The Greek Titans endpoint is accessible via:

GET https://thegreekmythapi.vercel.app/api/titans

This endpoint retrieves information about titans from Greek mythology, including their names, descriptions, attributes, and associated imagery.

Authentication

Currently, the API does not require authentication, making it easy to start fetching data right away. Simply use the base URL provided in your requests.

Response Structure

The response from the /api/titans endpoint follows this structure:

{
  "Titans": [
    {
      "name": "Cronus",
      "description": "Titan ruler of the universe until overthrown by his son, Zeus.",
      "category": "Titan",
      "attributes": {
        "origin": "Son of Uranus and Gaia",
        "symbols": ["Sickle", "Hourglass"],
        "abode": "Before Zeus' reign: Mount Othrys, then Tartarus",
        "powers": ["Rulership of the universe", "Fear of his children's power"],
        "family": {
          "parents": ["Uranus", "Gaia"],
          "siblings": ["Titans"],
          "spouse": ["Rhea"]
        },
        "stories": ["Overthrow by Zeus", "Imprisonment in Tartarus"]
      },
      "image": "https://example.com/cronus.jpg",
      "id": 1
    }
    // More titans...
  ]
}

Each titan object includes attributes such as name, description, attributes (including parentage, symbols, abode, powers, family, notable_deeds), image, and id.

Accessing the Endpoint

Here are several ways to access the /api/titans endpoint:

Using JavaScript Fetch API

fetch("https://thegreekmythapi.vercel.app/api/titans")
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error("Error:", error));

Using Axios (JavaScript)

import axios from "axios";
 
axios
  .get("https://thegreekmythapi.vercel.app/api/titans")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error("Error:", error);
  });

Using Python with requests

import requests
 
response = requests.get("https://thegreekmythapi.vercel.app/api/titans")
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code}")

Using cURL

curl https://thegreekmythapi.vercel.app/api/titans

Project Examples

Here are some example projects that demonstrate how to use the Greek Titans API:

Titan of the Week Display

Create a web page that showcases a different titan each week, displaying their information and image.

// React component example
import React, { useState, useEffect } from "react";
import axios from "axios";
 
function TitanOfTheWeek() {
  const [titan, setTitan] = useState(null);
 
  useEffect(() => {
    axios
      .get("https://thegreekmythapi.vercel.app/api/titans")
      .then((response) => {
        const titans = response.data.Titans;
        const randomTitan = titans[Math.floor(Math.random() * titans.length)];
        setTitan(randomTitan);
      })
      .catch((error) => console.error("Error:", error));
  }, []);
 
  if (!titan) return <div>Loading...</div>;
 
  return (
    <div>
      <h1>{titan.name}</h1>
      <img src={titan.image} alt={titan.name} />
      <p>{titan.description}</p>
      {/* Display more titan information */}
    </div>
  );
}

Titan Family Tree Visualization

Develop a visual representation of the family relationships among titans using a library like D3.js.

// D3.js example (simplified)
import * as d3 from "d3";
 
fetch("https://thegreekmythapi.vercel.app/api/titans")
  .then((response) => response.json())
  .then((data) => {
    const titans = data.Titans;
 
    // Create nodes and links based on family relationships
    const nodes = titans.map((titan) => ({ id: titan.name }));
    const links = [];
 
    titans.forEach((titan) => {
      if (titan.attributes.family) {
        titan.attributes.family.children.forEach((child) => {
          links.push({ source: titan.name, target: child });
        });
      }
    });
 
    // Set up D3 force simulation
    const simulation = d3
      .forceSimulation(nodes)
      .force(
        "link",
        d3.forceLink(links).id((d) => d.id)
      )
      .force("charge", d3.forceManyBody())
      .force("center", d3.forceCenter(width / 2, height / 2));
 
    // Render the nodes and links
    // (Add D3 code to create SVG elements and update their positions)
  });

Titan Quiz Game

Create a quiz game where users can test their knowledge about Greek Titans using the API data. The game presents questions about different titans, their attributes, and stories, allowing users to select answers from multiple choices.

// React component example
import React, { useState, useEffect } from "react";
import axios from "axios";
 
function TitanQuizGame() {
  const [questions, setQuestions] = useState([]);
  const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
  const [score, setScore] = useState(0);
  const [gameOver, setGameOver] = useState(false);
 
  useEffect(() => {
    axios
      .get("https://thegreekmythapi.vercel.app/api/titans")
      .then((response) => {
        const titans = response.data.Titans;
 
        // Generate quiz questions based on titan data
        const quizQuestions = titans.map((titan) => ({
          question: `What is ${titan.name}'s attribute?`,
          options: titan.attributes.symbols,
          correctAnswer: titan.attributes.symbols[0], // Assuming first symbol is correct
        }));
 
        setQuestions(quizQuestions);
      })
      .catch((error) => console.error("Error:", error));
  }, []);
 
  const handleAnswer = (selectedOption) => {
    const currentQuestion = questions[currentQuestionIndex];
 
    if (selectedOption === currentQuestion.correctAnswer) {
      setScore(score + 1);
    }
 
    // Move to the next question or end the game if no more questions
    if (currentQuestionIndex + 1 < questions.length) {
      setCurrentQuestionIndex(currentQuestionIndex + 1);
    } else {
      setGameOver(true);
    }
  };
 
  if (questions.length === 0) return <div>Loading...</div>;
 
  return (
    <div>
      {!gameOver ? (
        <div>
          <h2>Question {currentQuestionIndex + 1}</h2>
          <p>{questions[currentQuestionIndex].question}</p>
          <div>
            {questions[currentQuestionIndex].options.map((option, index) => (
              <button key={index} onClick={() => handleAnswer(option)}>
                {option}
              </button>
            ))}
          </div>
        </div>
      ) : (
        <div>
          <h2>Quiz Over!</h2>
          <p>
            Your score: {score} out of {questions.length}
          </p>
        </div>
      )}
    </div>
  );
}
 
export default TitanQuizGame;

These project examples demonstrate various ways to utilize the Greek Titans API in web development, data visualization, and educational contexts. Each example showcases a unique approach to integrating and utilizing the rich content provided by the API.