Skip to main content

fetcher

Callable

  • fetcher<JSON>(input: RequestInfo, init?: RequestInit): Promise<JSON>

  • Performs a fetch operation and returns the response data as JSON. Throws an error if the response is not successful (HTTP status code other than 2xx).

    @example
    // Perform a fetch request to retrieve JSON data
    fetcher<Data>("https://api.example.com/data", { method: "GET" })
    .then(data => {
    console.log("Data:", data);
    })
    .catch(error => {
    console.error("Error:", error);
    });

    Type parameters

    • JSON = any

      The type of the JSON response data.