Fetch | useWeb (original) (raw)

The Fetch API.

# State

The useFetch function exposes the following reactive state:

State Type Description
error Boolean If the request resulted in a non 200 status code.
headers Record<string, string> The response headers.
isLoading Boolean If the request is pending.
response any The response body as JSON or the raw response body as a string (depending on the content-type).
status number The HTTP status code.
statusText number The HTTP status text, eg: "OK" for 200.
success Boolean If the request is successful. i.e resulted in 200 status code.
type string Response type.

# Methods

The useFetch function exposes the following methods:

Signature Description
cancel Cancels the fetch request if browser supports AbortController, otherwise the request will complete but will not update the state.

# Example

TODO: useFetch example