Safe request
Put the endpoint and method in a request object instead of choosing a convenience method.
import { Http, problem } from "fetchzen";const api = Http.create(`${location.origin}/api/examples/`, { cache: false, secure: false, preset: problem,});const { data, error } = await api.safe.request({ endpoint: "status", method: "GET", params: { code: "422" }, retry: 0,});if (error) console.error(error);else console.log(data);Ready. No request sent.
Result
Choose Run to see the response.
Event log
No events yet.
What to notice
Section titled “What to notice”The primitive has the same data/error contract as safe.get.
This site’s demo status endpoint deliberately returns the selected failure; replace it with your API for real usage.
Next: safe errors or configuration.