Skip to content

NPM-Workbench/stoicism-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stoicism-banner npm downloads license

stoicism-api-client

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.

📦 Installation

npm install stoicism-api-client

🎲 Features

  1. Fetch random Stoic quotes: Retrieve timeless wisdom from Stoic philosophers like Marcus Aurelius, Seneca, and Epictetus.
  2. Lightweight & Fast: Minimal implementation with no unnecessary overhead.
  3. Zero dependencies: No external libraries required — uses native web APIs.
  4. Simple API surface: One function, one responsibility. Easy to learn and use.
  5. Type-safe (TypeScript support): Includes TypeScript typings for better developer experience.
  6. 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.

🔤 Example Usage

  1. 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
}
*/

📗 Test Coverage

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 |
----------|---------|----------|---------|---------|-------------------

📘 Contributing

Contributions, suggestions, and improvements are welcome.
Feel free to open issues or pull requests.

❤️ Support

Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.