Hooks

Add lifecycle callbacks to a client for this site’s demo API.

import { Http, envelope } from "fetchzen";
const api = Http.create(`${location.origin}/api/examples/`, {
cache: false, secure: false, preset: envelope,
hooks: {
request: [() => { console.log("request"); }],
response: [(response) => { console.log(response.status); }],
error: [() => { console.log("error"); }],
},
});
await api.get("echo", { params: { name: "Ada" }, retry: 0 });
Try this requestHook trace
Request parameters

Only Run sends a request to this site's demo API. Use synthetic data only; do not send secrets or personal files. Uploads are counted, not stored.

Ready. No request sent.

Result

Choose Run to see the response.
Event log
No events yet.

Request hooks surround a logical request, not each transport attempt. The panel logs sends separately using an injected Fetch transport. echo is a demo endpoint, not a service supplied by the library.

Next: retries or configuration.