Created
January 26, 2025 03:15
-
-
Save jorgeasaurus/896bdd06fa0c1aa66b7bc9e9edb5d1d9 to your computer and use it in GitHub Desktop.
Fetches a random Stoicism quote from a free API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-StoicQuote { | |
<# | |
.SYNOPSIS | |
Fetches a random Stoicism quote from the Stoic API. | |
.DESCRIPTION | |
This function retrieves a random Stoicism quote from the API and displays the | |
author and quote to the user. The API does not require authentication. | |
.EXAMPLE | |
Get-StoicQuote | |
Fetches and displays a random Stoicism quote. | |
#> | |
try { | |
# Define the API endpoint | |
$url = "https://stoic.tekloon.net/stoic-quote" | |
# Make the API request | |
$response = Invoke-RestMethod -Uri $url -Method Get | |
# Parse and display the quote | |
if ($response.data) { | |
$quote = $response.data.quote | |
$author = $response.data.author | |
Write-Output "Quote: '$quote'" | |
Write-Output "Author: $author" | |
} else { | |
Write-Output "No quote was retrieved. The response format might have changed." | |
} | |
} catch { | |
# Handle any errors that occur during the API call | |
Write-Error "An error occurred while fetching the quote: $_" | |
} | |
} |
Author
jorgeasaurus
commented
Jan 26, 2025

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment