Class: PostOrPostsFetchStrategy<T, P, R>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:53
This fetch strategy does not support extracting url params from the url
Extends
AbstractFetchStrategy<T[],P,R>
Type Parameters
T
T extends PostEntity = PostEntity
P
P extends PostOrPostsParams = PostOrPostsParams
R
R extends PostOrPostsFetchStrategyResult<T> = PostOrPostsFetchStrategyResult<T>
Constructors
Constructor
new PostOrPostsFetchStrategy<
T,P,R>(baseURL?,defaultParams?):PostOrPostsFetchStrategy<T,P,R>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:169
The strategy constructor
Parameters
baseURL?
string
The base URL of the API
defaultParams?
Partial<P>
(optional) list of default params
Returns
PostOrPostsFetchStrategy<T, P, R>
Inherited from
AbstractFetchStrategy.constructor
Properties
baseURL
baseURL:
string=''
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:155
The base URL where the API is located
Inherited from
defaultParams
defaultParams:
Partial<Params> ={}
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:145
The Default Params
Inherited from
AbstractFetchStrategy.defaultParams
endpoint
endpoint:
string=''
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:150
Holds the current endpoint for the strategy
Inherited from
AbstractFetchStrategy.endpoint
optimizeYoastPayload
optimizeYoastPayload:
boolean=false
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:64
postsStrategy
postsStrategy:
PostsArchiveFetchStrategy
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:62
postStrategy
postStrategy:
SinglePostFetchStrategy
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:60
urlParams
urlParams:
Partial<P> ={}
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:58
Methods
buildEndpointURL()
buildEndpointURL(
params):string
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:246
Builds the final endpoint URL based on the passed parameters
Parameters
params
Partial<Params>
The params to add to the request
Returns
string
The endpoint URL.
Inherited from
AbstractFetchStrategy.buildEndpointURL
fetchArchive()
fetchArchive(
url,params,options?):Promise<{isCached?:boolean;pageInfo:PageInfo;queriedObject:QueriedObject;result:R; }>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:158
Parameters
url
string
params
options?
Partial<FetchOptions>
Returns
Promise<{ isCached?: boolean; pageInfo: PageInfo; queriedObject: QueriedObject; result: R; }>
fetcher()
fetcher(
url,params,options?):Promise<FetchResponse<R>>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:171
The default fetcher function
The default fetcher function handles authentication headers and errors from the API.
A custom strategy can override this function to run additional logic before or after the fetch call
Parameters
url
string
The URL to fetch
params
Partial<P>
The request params
options?
Partial<FetchOptions>
The fetcher options
Returns
Promise<FetchResponse<R>>
Overrides
fetchSingle()
fetchSingle(
url,params,options?):Promise<{isCached?:boolean;pageInfo:PageInfo;queriedObject:QueriedObject;result:R; }>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:145
Parameters
url
string
params
options?
Partial<FetchOptions>
Returns
Promise<{ isCached?: boolean; pageInfo: PageInfo; queriedObject: QueriedObject; result: R; }>
filterData()
filterData(
data,filterOptions?):FetchResponse<R>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:412
Filters the data returned from the API by excluding fields that are not needed in order to reduce payload size.
Parameters
data
The data to filter
filterOptions?
Filter options
Returns
The filtered data
Inherited from
AbstractFetchStrategy.filterData
get()
get(
params):Promise<FetchResponse<R>>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:477
This is a simple wrapper to quickly fetch data from the API given a set of params
Usage
import { PostsArchiveFetchStrategy } from '@headstartwp/core';
new PostsArchiveFetchStrategy('http://my-wp-url.com').get({perPage: 10});
Parameters
params
Partial<Params> = {}
The endpoint params
Returns
Promise<FetchResponse<R>>
Inherited from
getAuthHeader()
getAuthHeader(
options):string
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:282
Parameters
options
Partial<FetchOptions> = {}
Returns
string
Inherited from
AbstractFetchStrategy.getAuthHeader
getCacheKey()
getCacheKey(
params):object
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:442
Returns the cache key with both the endpoint and the sourceUrl to distinguish between multiple sites
Parameters
params
Partial<Params>
The request params
Returns
object
The cache key object
args
args:
Partial<P> &object
Type declaration
sourceUrl
sourceUrl:
string
url
url:
string
Inherited from
AbstractFetchStrategy.getCacheKey
getDefaultEndpoint()
getDefaultEndpoint():
string
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:66
A method that must be implemented by concrete implementations which returns the default endpoint for the strategy
Returns
string
Overrides
AbstractFetchStrategy.getDefaultEndpoint
getDefaultParams()
getDefaultParams():
Partial<Params>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:208
Returns
Partial<Params>
Inherited from
AbstractFetchStrategy.getDefaultParams
getEndpoint()
getEndpoint():
string
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:200
Returns the endpoint of the strategy. If no endpoint has been set at runtime, returns the default endpoint
Returns
string
The current endpoint for the strategy
Inherited from
AbstractFetchStrategy.getEndpoint
getParamsFromURL()
getParamsFromURL(
path,params):Partial<P>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:70
Returns the supported params from the URL if present.
These params are passed to buildEndpointURL. If the strategy does not support
mapping url params to endpoint params, it should return an empty object.
Parameters
path
string
The Path name
params
Partial<P> = {}
The non-url params
Returns
Partial<P>
params extracted from the URL
Overrides
AbstractFetchStrategy.getParamsFromURL
getPreviewAuthHeader()
getPreviewAuthHeader(
options):string
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:273
Parameters
options
Partial<FetchOptions> = {}
Returns
string
Inherited from
AbstractFetchStrategy.getPreviewAuthHeader
getPreviewHeaderName()
getPreviewHeaderName(
options):"X-HeadstartWP-Authorization"|"Authorization"
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:267
Parameters
options
Partial<FetchOptions> = {}
Returns
"X-HeadstartWP-Authorization" | "Authorization"
Inherited from
AbstractFetchStrategy.getPreviewHeaderName
getQueriedObject()
getQueriedObject(
response,params):object
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:400
Parameters
response
FetchResponse<T[]>
params
Partial<Params>
Returns
object
Inherited from
AbstractFetchStrategy.getQueriedObject
isMainQuery()
isMainQuery(
path,nonUrlParams):boolean
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:83
Checks if this is the main query for a page
Parameters
path
string
The page name
nonUrlParams
Partial<P>
The non-url params
Returns
boolean
Overrides
AbstractFetchStrategy.isMainQuery
normalizeForCache()
normalizeForCache(
data,params):NormalizedDataForCache<R,P>
Defined in: packages/core/src/data/strategies/PostOrPostsFetchStrategy.ts:90
Normalize data for cache.
Parameters
data
The fetch response data
params
Partial<P>
The request params
Returns
NormalizedDataForCache<R, P>
Overrides
AbstractFetchStrategy.normalizeForCache
prepareResponse()
prepareResponse(
response,params):FetchResponse<R>
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:259
Parameters
response
FetchResponse<T[]>
params
Partial<Params>
Returns
Inherited from
AbstractFetchStrategy.prepareResponse
setBaseURL()
setBaseURL(
url):void
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:190
Parameters
url
undefined | string
Returns
void
Inherited from
AbstractFetchStrategy.setBaseURL
setEndpoint()
setEndpoint(
endpoint):void
Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:186
The strategy can switch endpoints at runtime if needed.
E.g: The actual endpoint for a post depends on its post_type
Parameters
endpoint
string
The endpoint to fetch
Returns
void