stoicism-api-client is a lightweight, zero-dependency JavaScript client that makes it easy to fetch Stoic quotes from a public API. Ideal for learning projects, bots, motivational apps, and philosophy enthusiasts.
npm install stoicism-api-client- Fetch random Stoic quotes: Retrieve timeless wisdom from Stoic philosophers like Marcus Aurelius, Seneca, and Epictetus.
- Lightweight & Fast: Minimal implementation with no unnecessary overhead.
- Zero dependencies: No external libraries required β uses native web APIs.
- Simple API surface: One function, one responsibility. Easy to learn and use.
- Type-safe (TypeScript support): Includes TypeScript typings for better developer experience.
- Beginner-friendly: Ideal for learning projects, demos, bots, and motivational apps.
## β οΈ Important: ##
This API cannot be accessed directly from the browser due to CORS restrictions enforced by the source API.
This package is intended to be used in server-side environments such as Node.js and other backend frameworks.
- Get A Random Stoic Quote
import { getStoicQuote } from "stoicism-api-client";
async function run() {
const response = await getStoicQuote();
if (response.code === "api-ok" && response.payload) {
console.log(response.payload);
} else {
console.error(response.message);
}
}
run();
// 200:OK
/*
{
"code": "api-ok",
"message": "No errors encountered",
"payload": {
"author": "Epictetus",
"quote": "Itβs not what happens to you, but how you react to it that matters."
}
}
*/
// Error
/*
{
"code": "api-fail",
"message": "Get Stoic Quote: Encountered Error!",
"payload": null
}
*/PASS src/get-stoic-quote/test/index.test.ts
getStoicQuote
β returns api-ok when response ok
β returns expected payload when response ok
β returns api-fail when response.ok is false
β returns api-fail when fetch throws
β targets the stoic quote endpoint
Test Suites: 1 passed, 1 total
Tests: 5 passed, 5 total
Snapshots: 0 total
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.ts | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
Contributions, suggestions, and improvements are welcome.
Feel free to open issues or pull requests.
- This package is open source and intended to provide reusable utilities for application development. It does not collect, store, transmit, sell, or share user data, and it does not include analytics, tracking, telemetry, cookies, local storage usage, backend services, or project-owned data collection mechanisms.
- For more details, including vulnerability reporting guidance and consumer security recommendations, please see the Security Policy.
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
