402.js
v1.0.0
Published
A lightweight wrapper around axios that adds 402 Payment Required retry hooks and pluggable paywall handlers.
Maintainers
Readme
402.js
A tiny axios wrapper that adds HTTP 402 (Payment Required) handling via a pluggable callback.
Install
npm install 402.js
# or
pnpm add 402.jsIf you're publishing this yourself, run
npm publishinside this folder.
Usage
import { createClient } from "402.js";
const client = createClient({
maxRetries: 1,
onPaymentRequired: async ({ config, error, attempt }) => {
// TODO: trigger your payment flow here (Stripe, Solana, Pump.fun, etc.)
// Return true to retry the request after payment succeeds.
console.log("402 received; attempt:", attempt);
return false;
}
});
const res = await client.get("https://api.example.com/protected");
console.log(res.data);API
createClient(options)
maxRetries(default1): number of times to retry after your payment callback returnstrue.onPaymentRequired(ctx)=>Promise<boolean>: called when a response is402. Returntrueto retry once payment succeeds.axiosConfig: passed toaxios.create().
Returns an object with { axios, get, post, put, patch, delete, request }.
License
MIT
