Class: PostsArchiveFetchStrategy<T, P>
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:206
The PostsArchiveFetchStrategy is used to fetch a collection of posts from any post type.
Note that custom post types and custom taxonomies should be defined in headless.config.js
This strategy supports extracting endpoint params from url E.g:
/category/cat-name/page/2maps to{ category: 'cat-name', page: 2 }/page/2/maps to{ page: 2 }/genre/genre-name/page/2maps to{ genre: 'genre-name', page: 2 }if agenretaxonomy is defined inheadless.config.js
See
getParamsFromURL to learn about url param mapping
Extends
AbstractFetchStrategy<T[],P>
Extended by
Type Parameters
T
T extends PostEntity = PostEntity
P
P extends PostsArchiveParams = PostsArchiveParams
Constructors
Constructor
new PostsArchiveFetchStrategy<
T,P>(baseURL?,defaultParams?):PostsArchiveFetchStrategy<T,P>
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
PostsArchiveFetchStrategy<T, P>
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
locale
locale:
string=''
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:212
optimizeYoastPayload
optimizeYoastPayload:
boolean=false
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:214
path
path:
string=''
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:210
Methods
buildEndpointURL()
buildEndpointURL(
params):string
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:293
Handles taxonomy filters and switch endpoint based on post type
Parameters
params
Partial<P>
The params to build the endpoint with
Returns
string
Overrides
AbstractFetchStrategy.buildEndpointURL
fetcher()
fetcher(
url,params,options):Promise<FetchResponse<T[]>>
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:397
Before fetching posts, we need handle taxonomy and authors.
If the headless plugin is not being used, then additional requests needs to be made to get authors and terms ids
Parameters
url
string
The URL to parse
params
Partial<P>
The params to build the endpoint with
options
Partial<FetchOptions> = {}
FetchOptions
Returns
Promise<FetchResponse<T[]>>
Overrides
filterData()
filterData(
data,options?):FetchResponse<T[]>
Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:549
Filters the data returned from the API by excluding fields that are not needed in order to reduce payload size.
Parameters
data
FetchResponse<T[]>
The data to filter
options?
FilterDataOptions<T[]>
Filter options
Returns
FetchResponse<T[]>
The filtered data
Overrides
AbstractFetchStrategy.filterData
get()
get(
params):Promise<FetchResponse<T[]>>
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<T[]>>
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