@wpkernel/core / defineResource
Function: defineResource()
Call Signature
function defineResource<T, TQuery, TRoutes>(config): ResourceObject<T, TQuery, TRoutes>;Define a resource with typed REST client
Creates a resource object with:
- Typed client methods (fetchList, fetch, create, update, remove)
- Store key for @wordpress/data registration
- Cache key generators for invalidation
- Route definitions
- Thin-flat API (useGet, useList, prefetchGet, prefetchList, invalidate, key)
- Grouped API (select., use., get., mutate., cache., storeApi., events.*)
Type Parameters
T
T = unknown
Resource entity type (e.g., TestimonialPost)
TQuery
TQuery = unknown
Query parameters type for list operations (e.g., { search?: string })
TRoutes
TRoutes extends ResourceRoutes = ResourceRoutes
Parameters
config
ResourceConfig<T, TQuery, TRoutes>
Resource configuration
Returns
ResourceObject<T, TQuery, TRoutes>
Resource object with client methods and metadata
Throws
DeveloperError if configuration is invalid
Call Signature
function defineResource<Config>(config): ResourceObject<InferResourceDefinition<Config>["entity"], InferResourceDefinition<Config>["query"], InferResourceDefinition<Config>["routes"]>;Define a resource with typed REST client
Creates a resource object with:
- Typed client methods (fetchList, fetch, create, update, remove)
- Store key for @wordpress/data registration
- Cache key generators for invalidation
- Route definitions
- Thin-flat API (useGet, useList, prefetchGet, prefetchList, invalidate, key)
- Grouped API (select., use., get., mutate., cache., storeApi., events.*)
Type Parameters
Config
Config extends ResourceConfig<unknown, unknown, ResourceRoutes>
Parameters
config
ConfigWithInferredCapabilities<Config>
Resource configuration
Returns
ResourceObject<InferResourceDefinition<Config>["entity"], InferResourceDefinition<Config>["query"], InferResourceDefinition<Config>["routes"]>
Resource object with client methods and metadata
Throws
DeveloperError if configuration is invalid
