Class: AuthorArchiveFetchStrategy<T, P>
@headstartwp/core.AuthorArchiveFetchStrategy
The AuthorArchiveFetchStrategy extends the PostsArchiveFetchStrategy and performs author archive requests
This strategy supports extracting endpoint params from url E.g:
/author-name/
maps to{ author: 'author-name' }
/author-name/page/2
maps to{ author: 'author-name', page: 2 }
Type parameters
Name | Type |
---|---|
T | extends PostEntity = PostEntity |
P | extends PostsArchiveParams = PostsArchiveParams |
Hierarchy
PostsArchiveFetchStrategy
<T
,P
>↳
AuthorArchiveFetchStrategy
Constructors
constructor
• new AuthorArchiveFetchStrategy<T
, P
>(baseURL?
, defaultParams?
)
The strategy constructor
Type parameters
Name | Type |
---|---|
T | extends PostEntity = PostEntity |
P | extends PostsArchiveParams = PostsArchiveParams |
Parameters
Name | Type | Description |
---|---|---|
baseURL? | string | The base URL of the API |
defaultParams? | Partial <P > | (optional) list of default params |
Inherited from
PostsArchiveFetchStrategy.constructor
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:145
Properties
baseURL
• baseURL: string
= ''
The base URL where the API is located
Inherited from
PostsArchiveFetchStrategy.baseURL
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:131
defaultParams
• defaultParams: Partial
<P
> = {}
The Default Params
Inherited from
PostsArchiveFetchStrategy.defaultParams
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:121
endpoint
• endpoint: string
= ''
Holds the current endpoint for the strategy
Inherited from
PostsArchiveFetchStrategy.endpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:126
locale
• locale: string
= ''
Inherited from
PostsArchiveFetchStrategy.locale
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:212
path
• path: string
= ''
Inherited from
PostsArchiveFetchStrategy.path
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:210
Methods
buildEndpointURL
▸ buildEndpointURL(params
): string
Handles taxonomy filters and switch endpoint based on post type
Parameters
Name | Type | Description |
---|---|---|
params | Partial <P > | The params to build the endpoint with |
Returns
string
Inherited from
PostsArchiveFetchStrategy.buildEndpointURL
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:289
fetcher
▸ fetcher(url
, params
, options?
): Promise
<FetchResponse
<T
[]>>
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
Name | Type | Description |
---|---|---|
url | string | The URL to parse |
params | Partial <P > | The params to build the endpoint with |
options | Partial <FetchOptions > | FetchOptions |
Returns
Promise
<FetchResponse
<T
[]>>
Inherited from
PostsArchiveFetchStrategy.fetcher
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:393
filterData
▸ filterData(data
, options?
): FetchResponse
<T
[]>
Filters the data returned from the API by excluding fields that are not needed in order to reduce payload size.
Parameters
Name | Type | Description |
---|---|---|
data | FetchResponse <T []> | The data to filter |
options? | FilterDataOptions <T []> | Filter options |
Returns
FetchResponse
<T
[]>
The filtered data
Inherited from
PostsArchiveFetchStrategy.filterData
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:530
get
▸ get(params?
): Promise
<FetchResponse
<T
[]>>
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
Name | Type | Description |
---|---|---|
params | Partial <P > | The endpoint params |
Returns
Promise
<FetchResponse
<T
[]>>
Inherited from
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:444
getAuthHeader
▸ getAuthHeader(options?
): string
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
string
Inherited from
PostsArchiveFetchStrategy.getAuthHeader
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:258
getCacheKey
▸ getCacheKey(params
): Object
Returns the cache key with both the endpoint and the sourceUrl to distinguish between multiple sites
Parameters
Name | Type | Description |
---|---|---|
params | Partial <P > | The request params |
Returns
Object
The cache key object
Name | Type |
---|---|
args | Partial <P > & { sourceUrl : string } |
url | string |
Inherited from
PostsArchiveFetchStrategy.getCacheKey
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:409
getDefaultEndpoint
▸ getDefaultEndpoint(): string
A method that must be implemented by concrete implementations which returns the default endpoint for the strategy
Returns
string
Inherited from
PostsArchiveFetchStrategy.getDefaultEndpoint
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:214
getDefaultParams
▸ getDefaultParams(): Partial
<P
>
Returns
Partial
<P
>
Inherited from
PostsArchiveFetchStrategy.getDefaultParams
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:218
getEndpoint
▸ getEndpoint(): string
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
PostsArchiveFetchStrategy.getEndpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:176
getParamsFromURL
▸ getParamsFromURL(path
, nonUrlParams?
): Partial
<P
>
This strategy automatically extracts taxonomy filters, date filters and pagination params from the URL
It also takes into account the custom taxonomies specified in headless.config.js
Parameters
Name | Type | Description |
---|---|---|
path | string | The URL path to extract params from |
nonUrlParams | Partial <P > |
Returns
Partial
<P
>
Overrides
PostsArchiveFetchStrategy.getParamsFromURL
Defined in
packages/core/src/data/strategies/AuthorArchiveFetchStrategy.ts:20
getPreviewAuthHeader
▸ getPreviewAuthHeader(options?
): string
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
string
Inherited from
PostsArchiveFetchStrategy.getPreviewAuthHeader
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:249
getPreviewHeaderName
▸ getPreviewHeaderName(options?
): "X-HeadstartWP-Authorization"
| "Authorization"
Parameters
Name | Type |
---|---|
options | Partial <FetchOptions > |
Returns
"X-HeadstartWP-Authorization"
| "Authorization"
Inherited from
PostsArchiveFetchStrategy.getPreviewHeaderName
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:243
getQueriedObject
▸ getQueriedObject(response
, params
): QueriedObject
Returns the queried object if applicable (e.g if querying by category, tag, author or custom taxonomy term)
Parameters
Name | Type | Description |
---|---|---|
response | FetchResponse <T []> | The response from the API |
params | Partial <P > | The request params |
Returns
Inherited from
PostsArchiveFetchStrategy.getQueriedObject
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:461
isMainQuery
▸ isMainQuery(path
, nonUrlParams
): boolean
Checks if this is the main query for a page
Parameters
Name | Type | Description |
---|---|---|
path | string | The page name |
nonUrlParams | Partial <P > | The non-url params |
Returns
boolean
Inherited from
PostsArchiveFetchStrategy.isMainQuery
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:207
normalizeForCache
▸ normalizeForCache(data
, params
): NormalizedDataForCache
<T
[], P
>
Normalize data for cache.
Parameters
Name | Type | Description |
---|---|---|
data | FetchResponse <T []> | The fetch response data |
params | Partial <P > | The request params |
Returns
NormalizedDataForCache
<T
[], P
>
Inherited from
PostsArchiveFetchStrategy.normalizeForCache
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:419
prepareResponse
▸ prepareResponse(response
, params
): FetchResponse
<T
[]>
Parameters
Name | Type |
---|---|
response | FetchResponse <T []> |
params | Partial <P > |
Returns
FetchResponse
<T
[]>
Inherited from
PostsArchiveFetchStrategy.prepareResponse
Defined in
packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:327
setBaseURL
▸ setBaseURL(url?
): void
Parameters
Name | Type | Default value |
---|---|---|
url | undefined | string | '' |
Returns
void
Inherited from
PostsArchiveFetchStrategy.setBaseURL
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:166
setEndpoint
▸ setEndpoint(endpoint
): void
The strategy can switch endpoints at runtime if needed.
E.g: The actual endpoint for a post depends on its post_type
Parameters
Name | Type | Description |
---|---|---|
endpoint | string | The endpoint to fetch |
Returns
void
Inherited from
PostsArchiveFetchStrategy.setEndpoint
Defined in
packages/core/src/data/strategies/AbstractFetchStrategy.ts:162