A tiny JavaScript/TypeScript client for the Yes As A Service API — fetch random positive affirmations with a single request.
npm install yes-as-a-service-api-client- Zero configuration
- No inputs required
- Minimal surface area
- Predictable API responses
- Native fetch support
- TypeScript-first
import { getAYes } from 'yes-as-a-service-api-client';
async function run() {
const response = await getAYes();
if (response.code === 'api-ok') {
console.log(response.payload?.affirmation);
} else {
console.error(response.message);
}
}
run();
// Sample Success Response
/*
{
"code": "api-ok",
"message": "No errors encountered, check payload",
"payload": {
"affirmation": "Yes! Everything is working exactly as intended."
}
}
*/
// Sample Error Response
/*{
"code": "api-fail",
"message": "Something went wrong",
"payload": null
}*/PASS src/get-a-yes/index.test.ts
getAYes
✓ returns api-ok and payload when fetch resolves with ok=true
✓ returns api-fail when response.ok is false
✓ returns api-fail when fetch throws
✓ returns api-fail when json parsing fails
✓ returns object payload with affirmation on success (payload test)
✓ returns null payload on fetch error (payload null test)
----------|---------|----------|---------|---------|-------------------
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.
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
