ResourcesApi
Base interface for all resource API operations.
Provides type-safe methods for interacting with Kubernetes and Rancher resources. Used by both cluster-scoped and management-scoped APIs, and can be extended by custom store implementations (e.g. Harvester, Epinio).
The examples below all use resources.cluster. Every method works the same way on the other
APIs, so substitute the one you need - resources.mgmt for management resources, for example.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const deployment = await api.find(K8S.DEPLOYMENT, 'default/my-app');
Methods
create()
create<T, I>(data): Promise<I>;
Creates a new resource.
The data object must include a type property identifying the resource type.
This is a raw HTTP operation — it does not check permissions or update the store cache.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = SteveResource<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
data
The resource data to create. Must include a type property (examples in K8S). See also CreateResourceData.
Returns
Promise<I>
The created resource instance.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const configMap = await api.create({
type: K8S.CONFIG_MAP,
metadata: { name: 'my-config', namespace: 'default' },
data: { key: 'value' }
});
delete()
delete(resourceType, resourceId): Promise<void>;
Deletes a resource by type and ID using HTTP DELETE.
This is a raw HTTP operation — it does not check permissions or update the store cache.
Parameters
resourceType
string
The type of the resource (examples in K8S). See also ResourceType.
resourceId
string
The unique identifier. If namespaced, use namespace/name format.
Returns
Promise<void>
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
await api.delete(K8S.CONFIG_MAP, 'default/my-config');
find()
find<T, I>(
resourceType,
resourceId,
options?): Promise<I>;
Finds a specific resource by its type and ID.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ResourceInstance<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resource to find (examples in K8S). See also ResourceType.
resourceId
string
The unique identifier of the resource to find. If the resource is namespaced, this should be in the format namespace/name.
options?
Optional find arguments
Returns
Promise<I>
The found resource item or null if not found.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
// Namespaced resource - ID must be in "namespace/name" format
const pod = await api.find(K8S.POD, 'default/my-pod-123');
// Cluster-scoped resource - ID is just the name
const node = await api.find(K8S.NODE, 'worker-1');
findAll()
findAll<T, I>(resourceType, options?): Promise<I[]>;
Fetches all resources of a specific type with advanced options. This method provides additional capabilities like incremental loading and namespace filtering.
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods
I
I = ResourceInstance<T>
An override for the response type. By default this uses T and supplements the response, or by supplying a value ignores T
Parameters
resourceType
string
The type of the resources to find (examples in K8S). See also ResourceType.
options?
Optional advanced fetch options (incremental loading, namespace filtering, etc.)
Returns
Promise<I[]>
An array of resource items or an empty array if none are found.
Example
import { useResources, K8S } from '@shell/apis';
const resources = useResources();
// Substitute `resources.cluster` for the API you want, e.g. `resources.mgmt` for management resources
const api = resources.cluster;
const allPods = await api.findAll(K8S.POD, {
namespaced: ['default', 'kube-system']
});
findFiltered()
Call Signature
findFiltered<T, I>(resourceType, options): Promise<I>;
Finds resources using pagination mode with server-side filtering, sorting, and pagination.
The response is not cached
Type Parameters
T
T = Record<string, any>
Your specific resource type. Rancher will supplement the response with additional properties and methods