A tiny JavaScript client for the “No As A Service” API (https://naas.isalman.dev/no) that delivers random rejection reasons with a consistent, typed response format.
npm install no-as-a-service-api-client- Zero configurations
- Native
fetch(no dependencies) - Fully typed responses
- Consistent API success/error wrapper
- Works in modern browsers and Node.js (ES6 Imports)
import { getANo } from 'no-as-a-service-api-client';
async function run() {
const response = await getANo();
if (response.code === 'api-ok') {
console.log(response.payload?.reason);
} else {
console.error(response.message);
}
}
run();
// Sample Success Response
/*
{
"code": "api-ok",
"message": "No errors encountered, check payload",
"payload": {
"reason": "I didn’t receive the memo that I was supposed to care."
}
}
*/
// Sample Error Response
/*
{
"code": "api-fail",
"message": "Something went wrong",
"payload": null
}
*/PASS src/get-a-no/index.test.ts
getANo
✓ 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 reason 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.
