httpResource
makes a reactive HTTP request and exposes the request status and response value as
a WritableResource
. By default, it assumes that the backend will return JSON data. To make a
request that expects a different kind of data, you can use a sub-constructor of httpResource
,
such as httpResource.text
.
function httpResource<TResult = unknown>(url: string | (() => string | undefined), options: HttpResourceOptions<TResult, unknown> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
Create a Resource
that fetches data with an HTTP GET request to the given URL.
If a reactive function is passed for the URL, the resource will update when the URL changes via signals.
Uses HttpClient
to make requests and supports interceptors, testing, and the other features
of the HttpClient
API. Data is parsed as JSON by default - use a sub-function of
httpResource
, such as httpResource.text()
, to parse the response differently.
string | (() => string | undefined)
HttpResourceRef<TResult>
function httpResource<TResult = unknown>(url: string | (() => string | undefined), options?: HttpResourceOptions<TResult, unknown> | undefined): HttpResourceRef<TResult | undefined>;
Create a Resource
that fetches data with an HTTP GET request to the given URL.
If a reactive function is passed for the URL, the resource will update when the URL changes via signals.
Uses HttpClient
to make requests and supports interceptors, testing, and the other features
of the HttpClient
API. Data is parsed as JSON by default - use a sub-function of
httpResource
, such as httpResource.text()
, to parse the response differently.
string | (() => string | undefined)
HttpResourceRef<TResult | undefined>
function httpResource<TResult = unknown>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options: HttpResourceOptions<TResult, unknown> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
Create a Resource
that fetches data with the configured HTTP request.
If a reactive function is passed for the request, the resource will update when the request changes via signals.
Uses HttpClient
to make requests and supports interceptors, testing, and the other features
of the HttpClient
API. Data is parsed as JSON by default - use a sub-function of
httpResource
, such as httpResource.text()
, to parse the response differently.
HttpResourceRef<TResult>
function httpResource<TResult = unknown>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options?: HttpResourceOptions<TResult, unknown> | undefined): HttpResourceRef<TResult | undefined>;
Create a Resource
that fetches data with the configured HTTP request.
If a reactive function is passed for the request, the resource will update when the request changes via signals.
Uses HttpClient
to make requests and supports interceptors, testing, and the other features
of the HttpClient
API. Data is parsed as JSON by default - use a sub-function of
httpResource
, such as httpResource.text()
, to parse the response differently.
HttpResourceRef<TResult | undefined>
function httpResource.arrayBuffer<TResult = ArrayBuffer>(url: string | (() => string | undefined), options: HttpResourceOptions<TResult, ArrayBuffer> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
string | (() => string | undefined)
HttpResourceRef<TResult>
function httpResource.arrayBuffer<TResult = ArrayBuffer>(url: string | (() => string | undefined), options?: HttpResourceOptions<TResult, ArrayBuffer> | undefined): HttpResourceRef<TResult | undefined>;
string | (() => string | undefined)
HttpResourceRef<TResult | undefined>
function httpResource.arrayBuffer<TResult = ArrayBuffer>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options: HttpResourceOptions<TResult, ArrayBuffer> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
HttpResourceRef<TResult>
function httpResource.arrayBuffer<TResult = ArrayBuffer>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options?: HttpResourceOptions<TResult, ArrayBuffer> | undefined): HttpResourceRef<TResult | undefined>;
HttpResourceRef<TResult | undefined>
function httpResource.blob<TResult = Blob>(url: string | (() => string | undefined), options: HttpResourceOptions<TResult, Blob> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
string | (() => string | undefined)
HttpResourceRef<TResult>
function httpResource.blob<TResult = Blob>(url: string | (() => string | undefined), options?: HttpResourceOptions<TResult, Blob> | undefined): HttpResourceRef<TResult | undefined>;
string | (() => string | undefined)
HttpResourceRef<TResult | undefined>
function httpResource.blob<TResult = Blob>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options: HttpResourceOptions<TResult, Blob> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
HttpResourceRef<TResult>
function httpResource.blob<TResult = Blob>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options?: HttpResourceOptions<TResult, Blob> | undefined): HttpResourceRef<TResult | undefined>;
HttpResourceRef<TResult | undefined>
function httpResource.text<TResult = string>(url: string | (() => string | undefined), options: HttpResourceOptions<TResult, string> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
string | (() => string | undefined)
HttpResourceRef<TResult>
function httpResource.text<TResult = string>(url: string | (() => string | undefined), options?: HttpResourceOptions<TResult, string> | undefined): HttpResourceRef<TResult | undefined>;
string | (() => string | undefined)
HttpResourceRef<TResult | undefined>
function httpResource.text<TResult = string>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options: HttpResourceOptions<TResult, string> & { defaultValue: NoInfer<TResult>; }): HttpResourceRef<TResult>;
HttpResourceRef<TResult>
function httpResource.text<TResult = string>(request: HttpResourceRequest | (() => HttpResourceRequest | undefined), options?: HttpResourceOptions<TResult, string> | undefined): HttpResourceRef<TResult | undefined>;
HttpResourceRef<TResult | undefined>