Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>TMKOC Quotes API Demo</title> | |
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| padding: 20px; | |
| } | |
| .container { | |
| max-width: 1200px; | |
| margin: 0 auto; | |
| } | |
| .header { | |
| text-align: center; | |
| margin-bottom: 40px; | |
| animation: fadeInDown 1s ease-out; | |
| } | |
| .header h1 { | |
| color: white; | |
| font-size: 3rem; | |
| margin-bottom: 10px; | |
| text-shadow: 2px 2px 4px rgba(0,0,0,0.3); | |
| } | |
| .header p { | |
| color: rgba(255,255,255,0.9); | |
| font-size: 1.2rem; | |
| margin-bottom: 20px; | |
| } | |
| .api-info { | |
| background: rgba(255,255,255,0.1); | |
| backdrop-filter: blur(10px); | |
| border-radius: 15px; | |
| padding: 15px 25px; | |
| border: 1px solid rgba(255,255,255,0.2); | |
| display: inline-block; | |
| } | |
| .api-info code { | |
| color: #FFD700; | |
| font-weight: bold; | |
| } | |
| .demo-section { | |
| background: rgba(255,255,255,0.95); | |
| border-radius: 20px; | |
| padding: 30px; | |
| margin-bottom: 30px; | |
| box-shadow: 0 20px 40px rgba(0,0,0,0.1); | |
| animation: fadeInUp 1s ease-out; | |
| } | |
| .section-title { | |
| font-size: 1.8rem; | |
| color: #333; | |
| margin-bottom: 20px; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .controls { | |
| display: flex; | |
| flex-wrap: wrap; | |
| gap: 15px; | |
| margin-bottom: 25px; | |
| } | |
| .btn { | |
| padding: 12px 24px; | |
| border: none; | |
| border-radius: 25px; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| box-shadow: 0 4px 15px rgba(0,0,0,0.1); | |
| } | |
| .btn-primary { | |
| background: linear-gradient(45deg, #FF6B6B, #FF8E53); | |
| color: white; | |
| } | |
| .btn-secondary { | |
| background: linear-gradient(45deg, #4ECDC4, #44A08D); | |
| color: white; | |
| } | |
| .btn-accent { | |
| background: linear-gradient(45deg, #A8E6CF, #88D8A3); | |
| color: #333; | |
| } | |
| .btn:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 8px 25px rgba(0,0,0,0.2); | |
| } | |
| .input-group { | |
| display: flex; | |
| gap: 10px; | |
| margin-bottom: 15px; | |
| flex-wrap: wrap; | |
| } | |
| .form-input { | |
| flex: 1; | |
| min-width: 200px; | |
| padding: 12px 16px; | |
| border: 2px solid #e0e0e0; | |
| border-radius: 25px; | |
| font-size: 1rem; | |
| transition: all 0.3s ease; | |
| } | |
| .form-input:focus { | |
| outline: none; | |
| border-color: #667eea; | |
| box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); | |
| } | |
| .quote-display { | |
| background: linear-gradient(135deg, #667eea, #764ba2); | |
| color: white; | |
| padding: 30px; | |
| border-radius: 15px; | |
| margin: 20px 0; | |
| text-align: center; | |
| min-height: 150px; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .quote-display::before { | |
| content: '"'; | |
| font-size: 8rem; | |
| position: absolute; | |
| top: -20px; | |
| left: 20px; | |
| opacity: 0.1; | |
| font-family: serif; | |
| } | |
| .quote-text { | |
| font-size: 1.4rem; | |
| line-height: 1.6; | |
| margin-bottom: 15px; | |
| font-style: italic; | |
| } | |
| .quote-author { | |
| font-size: 1.1rem; | |
| font-weight: 600; | |
| opacity: 0.9; | |
| } | |
| .quote-tags { | |
| margin-top: 10px; | |
| } | |
| .tag { | |
| display: inline-block; | |
| background: rgba(255,255,255,0.2); | |
| padding: 4px 12px; | |
| border-radius: 15px; | |
| font-size: 0.8rem; | |
| margin: 2px; | |
| } | |
| .results-container { | |
| max-height: 400px; | |
| overflow-y: auto; | |
| border: 1px solid #e0e0e0; | |
| border-radius: 10px; | |
| padding: 15px; | |
| } | |
| .quote-item { | |
| background: #f8f9fa; | |
| padding: 15px; | |
| border-radius: 8px; | |
| margin-bottom: 10px; | |
| border-left: 4px solid #667eea; | |
| } | |
| .loading { | |
| text-align: center; | |
| padding: 40px; | |
| color: #666; | |
| } | |
| .spinner { | |
| display: inline-block; | |
| width: 30px; | |
| height: 30px; | |
| border: 3px solid #f3f3f3; | |
| border-top: 3px solid #667eea; | |
| border-radius: 50%; | |
| animation: spin 1s linear infinite; | |
| margin-bottom: 10px; | |
| } | |
| .error { | |
| background: #ffebee; | |
| color: #c62828; | |
| padding: 15px; | |
| border-radius: 8px; | |
| border-left: 4px solid #c62828; | |
| } | |
| .endpoints { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | |
| gap: 20px; | |
| margin-top: 20px; | |
| } | |
| .endpoint-card { | |
| background: #f8f9fa; | |
| padding: 20px; | |
| border-radius: 12px; | |
| border: 1px solid #e0e0e0; | |
| } | |
| .endpoint-method { | |
| background: #28a745; | |
| color: white; | |
| padding: 4px 8px; | |
| border-radius: 4px; | |
| font-size: 0.8rem; | |
| font-weight: bold; | |
| margin-bottom: 8px; | |
| display: inline-block; | |
| } | |
| .endpoint-url { | |
| font-family: 'Courier New', monospace; | |
| background: #e9ecef; | |
| padding: 8px 12px; | |
| border-radius: 6px; | |
| font-size: 0.9rem; | |
| word-break: break-all; | |
| } | |
| @keyframes fadeInDown { | |
| from { | |
| opacity: 0; | |
| transform: translateY(-30px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| @keyframes fadeInUp { | |
| from { | |
| opacity: 0; | |
| transform: translateY(30px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| @media (max-width: 768px) { | |
| .header h1 { | |
| font-size: 2rem; | |
| } | |
| .controls { | |
| flex-direction: column; | |
| } | |
| .input-group { | |
| flex-direction: column; | |
| } | |
| .form-input { | |
| min-width: unset; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <h1><i class="fas fa-quote-left"></i> TMKOC Quotes API</h1> | |
| <p>Explore quotes from the beloved Indian sitcom Taarak Mehta Ka Ooltah Chashmah</p> | |
| <div class="api-info"> | |
| <i class="fas fa-link"></i> Base URL: <code>https://tmkoc-quotes-api.onrender.com</code> | |
| </div> | |
| </div> | |
| <!-- Random Quote Section --> | |
| <div class="demo-section"> | |
| <h2 class="section-title"> | |
| <i class="fas fa-random"></i> | |
| Random Quotes | |
| </h2> | |
| <div class="controls"> | |
| <button class="btn btn-primary" onclick="getRandomQuote()"> | |
| <i class="fas fa-dice"></i> Get Random Quote | |
| </button> | |
| <button class="btn btn-secondary" onclick="getMultipleQuotes()"> | |
| <i class="fas fa-layer-group"></i> Get 3 Random Quotes | |
| </button> | |
| </div> | |
| <div id="randomQuoteDisplay" class="quote-display" style="display: none;"> | |
| <div class="quote-text" id="randomQuoteText"></div> | |
| <div class="quote-author" id="randomQuoteAuthor"></div> | |
| <div class="quote-tags" id="randomQuoteTags"></div> | |
| </div> | |
| <div id="multipleQuotesDisplay" class="results-container" style="display: none;"></div> | |
| </div> | |
| <!-- Character Filter Section --> | |
| <div class="demo-section"> | |
| <h2 class="section-title"> | |
| <i class="fas fa-user"></i> | |
| Filter by Character | |
| </h2> | |
| <div class="controls"> | |
| <button class="btn btn-accent" onclick="getQuotesByCharacter('Jethalal')">Jethalal</button> | |
| <button class="btn btn-accent" onclick="getQuotesByCharacter('Daya')">Daya</button> | |
| <button class="btn btn-accent" onclick="getQuotesByCharacter('Tapu')">Tapu</button> | |
| <button class="btn btn-accent" onclick="getQuotesByCharacter('Popatlal')">Popatlal</button> | |
| </div> | |
| <div class="input-group"> | |
| <input type="text" class="form-input" id="characterInput" placeholder="Enter character name..."> | |
| <button class="btn btn-primary" onclick="getQuotesByCharacterInput()"> | |
| <i class="fas fa-search"></i> Search | |
| </button> | |
| </div> | |
| <div id="characterQuotesDisplay" class="results-container" style="display: none;"></div> | |
| </div> | |
| <!-- Search Section --> | |
| <div class="demo-section"> | |
| <h2 class="section-title"> | |
| <i class="fas fa-search"></i> | |
| Search Quotes | |
| </h2> | |
| <div class="input-group"> | |
| <input type="text" class="form-input" id="searchAuthor" placeholder="Author name (optional)"> | |
| <input type="text" class="form-input" id="searchText" placeholder="Search text in quotes"> | |
| <button class="btn btn-primary" onclick="searchQuotes()"> | |
| <i class="fas fa-search"></i> Search | |
| </button> | |
| </div> | |
| <div id="searchResults" class="results-container" style="display: none;"></div> | |
| </div> | |
| <!-- API Endpoints Reference --> | |
| <div class="demo-section"> | |
| <h2 class="section-title"> | |
| <i class="fas fa-code"></i> | |
| API Endpoints Reference | |
| </h2> | |
| <div class="endpoints"> | |
| <div class="endpoint-card"> | |
| <div class="endpoint-method">GET</div> | |
| <div class="endpoint-url">/v1/quotes</div> | |
| <p>Get a random quote</p> | |
| </div> | |
| <div class="endpoint-card"> | |
| <div class="endpoint-method">GET</div> | |
| <div class="endpoint-url">/v1/quotes/{number}</div> | |
| <p>Get multiple random quotes</p> | |
| </div> | |
| <div class="endpoint-card"> | |
| <div class="endpoint-method">GET</div> | |
| <div class="endpoint-url">/v1/quotes/character/{author}</div> | |
| <p>Get quotes by character</p> | |
| </div> | |
| <div class="endpoint-card"> | |
| <div class="endpoint-method">GET</div> | |
| <div class="endpoint-url">/v1/quotes/tag/{tag}</div> | |
| <p>Get quotes by tag/category</p> | |
| </div> | |
| <div class="endpoint-card"> | |
| <div class="endpoint-method">GET</div> | |
| <div class="endpoint-url">/v1/quotes/search?author=X&text=Y</div> | |
| <p>Search quotes by author and/or text</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| const API_BASE = 'https://tmkoc-quotes-api.onrender.com/v1'; | |
| function showLoading(containerId) { | |
| const container = document.getElementById(containerId); | |
| container.style.display = 'block'; | |
| container.innerHTML = ` | |
| <div class="loading"> | |
| <div class="spinner"></div> | |
| <p>Loading quotes...</p> | |
| </div> | |
| `; | |
| } | |
| function showError(containerId, message) { | |
| const container = document.getElementById(containerId); | |
| container.style.display = 'block'; | |
| container.innerHTML = ` | |
| <div class="error"> | |
| <i class="fas fa-exclamation-triangle"></i> | |
| Error: ${message} | |
| </div> | |
| `; | |
| } | |
| function displaySingleQuote(quote) { | |
| document.getElementById('randomQuoteText').textContent = quote.quote; | |
| document.getElementById('randomQuoteAuthor').textContent = `— ${quote.author}`; | |
| const tagsContainer = document.getElementById('randomQuoteTags'); | |
| if (quote.tags && quote.tags.length > 0) { | |
| tagsContainer.innerHTML = quote.tags.map(tag => | |
| `<span class="tag">#${tag}</span>` | |
| ).join(''); | |
| } else { | |
| tagsContainer.innerHTML = ''; | |
| } | |
| document.getElementById('randomQuoteDisplay').style.display = 'flex'; | |
| } | |
| function displayMultipleQuotes(quotes, containerId) { | |
| const container = document.getElementById(containerId); | |
| container.style.display = 'block'; | |
| container.innerHTML = quotes.map(quote => ` | |
| <div class="quote-item"> | |
| <div style="font-size: 1.1rem; margin-bottom: 8px; font-style: italic;"> | |
| "${quote.quote}" | |
| </div> | |
| <div style="font-weight: 600; color: #667eea;"> | |
| — ${quote.author} | |
| </div> | |
| ${quote.tags ? ` | |
| <div style="margin-top: 8px;"> | |
| ${quote.tags.map(tag => `<span class="tag" style="background: #e3f2fd; color: #1976d2;">#${tag}</span>`).join('')} | |
| </div> | |
| ` : ''} | |
| </div> | |
| `).join(''); | |
| } | |
| async function makeAPICall(endpoint) { | |
| const response = await fetch(`${API_BASE}${endpoint}`); | |
| if (!response.ok) { | |
| throw new Error(`HTTP ${response.status}: ${response.statusText}`); | |
| } | |
| return await response.json(); | |
| } | |
| async function getRandomQuote() { | |
| try { | |
| document.getElementById('multipleQuotesDisplay').style.display = 'none'; | |
| showLoading('randomQuoteDisplay'); | |
| const quotes = await makeAPICall('/quotes'); | |
| document.getElementById('randomQuoteDisplay').style.display = 'none'; | |
| displaySingleQuote(quotes[0]); | |
| } catch (error) { | |
| showError('randomQuoteDisplay', error.message); | |
| } | |
| } | |
| async function getMultipleQuotes() { | |
| try { | |
| document.getElementById('randomQuoteDisplay').style.display = 'none'; | |
| showLoading('multipleQuotesDisplay'); | |
| const quotes = await makeAPICall('/quotes/3'); | |
| displayMultipleQuotes(quotes, 'multipleQuotesDisplay'); | |
| } catch (error) { | |
| showError('multipleQuotesDisplay', error.message); | |
| } | |
| } | |
| async function getQuotesByCharacter(character) { | |
| try { | |
| showLoading('characterQuotesDisplay'); | |
| const quotes = await makeAPICall(`/quotes/character/${encodeURIComponent(character)}`); | |
| displayMultipleQuotes(quotes, 'characterQuotesDisplay'); | |
| } catch (error) { | |
| showError('characterQuotesDisplay', error.message); | |
| } | |
| } | |
| async function getQuotesByCharacterInput() { | |
| const character = document.getElementById('characterInput').value.trim(); | |
| if (!character) { | |
| alert('Please enter a character name'); | |
| return; | |
| } | |
| await getQuotesByCharacter(character); | |
| } | |
| async function searchQuotes() { | |
| const author = document.getElementById('searchAuthor').value.trim(); | |
| const text = document.getElementById('searchText').value.trim(); | |
| if (!author && !text) { | |
| alert('Please enter either author name or search text'); | |
| return; | |
| } | |
| try { | |
| showLoading('searchResults'); | |
| const params = new URLSearchParams(); | |
| if (author) params.append('author', author); | |
| if (text) params.append('text', text); | |
| const quotes = await makeAPICall(`/quotes/search?${params.toString()}`); | |
| displayMultipleQuotes(quotes, 'searchResults'); | |
| } catch (error) { | |
| showError('searchResults', error.message); | |
| } | |
| } | |
| // Add enter key support for inputs | |
| document.getElementById('characterInput').addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| getQuotesByCharacterInput(); | |
| } | |
| }); | |
| document.getElementById('searchAuthor').addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| searchQuotes(); | |
| } | |
| }); | |
| document.getElementById('searchText').addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| searchQuotes(); | |
| } | |
| }); | |
| // Load a random quote on page load | |
| window.addEventListener('load', getRandomQuote); | |
| </script> | |
| </body> | |
| </html> |