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 });Ready. No request sent.
Result
Choose Run to see the response.
Event log
No events yet.
What to notice
Section titled “What to notice”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.