Skip to main content

Class: AuthorArchiveFetchStrategy<T, P>

Defined in: packages/core/src/data/strategies/AuthorArchiveFetchStrategy.ts:16

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 }

Extends

Type Parameters

T

T extends PostEntity = PostEntity

P

P extends PostsArchiveParams = PostsArchiveParams

Constructors

Constructor

new AuthorArchiveFetchStrategy<T, P>(baseURL?, defaultParams?): AuthorArchiveFetchStrategy<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

AuthorArchiveFetchStrategy<T, P>

Inherited from

PostsArchiveFetchStrategy.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

PostsArchiveFetchStrategy.baseURL


defaultParams

defaultParams: Partial<Params> = {}

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:145

The Default Params

Inherited from

PostsArchiveFetchStrategy.defaultParams


endpoint

endpoint: string = ''

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:150

Holds the current endpoint for the strategy

Inherited from

PostsArchiveFetchStrategy.endpoint


locale

locale: string = ''

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:212

Inherited from

PostsArchiveFetchStrategy.locale


optimizeYoastPayload

optimizeYoastPayload: boolean = false

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:214

Inherited from

PostsArchiveFetchStrategy.optimizeYoastPayload


path

path: string = ''

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:210

Inherited from

PostsArchiveFetchStrategy.path

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

Inherited from

PostsArchiveFetchStrategy.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[]>>

Inherited from

PostsArchiveFetchStrategy.fetcher


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

Inherited from

PostsArchiveFetchStrategy.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

PostsArchiveFetchStrategy.get


getAuthHeader()

getAuthHeader(options): string

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:282

Parameters

options

Partial<FetchOptions> = {}

Returns

string

Inherited from

PostsArchiveFetchStrategy.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

PostsArchiveFetchStrategy.getCacheKey


getDefaultEndpoint()

getDefaultEndpoint(): string

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:216

A method that must be implemented by concrete implementations which returns the default endpoint for the strategy

Returns

string

Inherited from

PostsArchiveFetchStrategy.getDefaultEndpoint


getDefaultParams()

getDefaultParams(): Partial<P>

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:220

Returns

Partial<P>

Inherited from

PostsArchiveFetchStrategy.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

PostsArchiveFetchStrategy.getEndpoint


getParamsFromURL()

getParamsFromURL(path, nonUrlParams): Partial<P>

Defined in: packages/core/src/data/strategies/AuthorArchiveFetchStrategy.ts:20

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

path

string

The URL path to extract params from

nonUrlParams

Partial<P> = {}

Returns

Partial<P>

Overrides

PostsArchiveFetchStrategy.getParamsFromURL


getPreviewAuthHeader()

getPreviewAuthHeader(options): string

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:273

Parameters

options

Partial<FetchOptions> = {}

Returns

string

Inherited from

PostsArchiveFetchStrategy.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

PostsArchiveFetchStrategy.getPreviewHeaderName


getQueriedObject()

getQueriedObject(response, params): QueriedObject

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:480

Returns the queried object if applicable (e.g if querying by category, tag, author or custom taxonomy term)

Parameters

response

FetchResponse<T[]>

The response from the API

params

Partial<P>

The request params

Returns

QueriedObject

Inherited from

PostsArchiveFetchStrategy.getQueriedObject


isMainQuery()

isMainQuery(path, nonUrlParams): boolean

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:231

Checks if this is the main query for a page

Parameters

path

string

The page name

nonUrlParams

Partial<Params>

The non-url params

Returns

boolean

Inherited from

PostsArchiveFetchStrategy.isMainQuery


normalizeForCache()

normalizeForCache(data, params): NormalizedDataForCache<T[], P>

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:452

Normalize data for cache.

Parameters

data

FetchResponse<T[]>

The fetch response data

params

Partial<Params>

The request params

Returns

NormalizedDataForCache<T[], P>

Inherited from

PostsArchiveFetchStrategy.normalizeForCache


prepareResponse()

prepareResponse(response, params): FetchResponse<T[]>

Defined in: packages/core/src/data/strategies/PostsArchiveFetchStrategy.ts:331

Parameters

response

FetchResponse<T[]>

params

Partial<P>

Returns

FetchResponse<T[]>

Inherited from

PostsArchiveFetchStrategy.prepareResponse


setBaseURL()

setBaseURL(url): void

Defined in: packages/core/src/data/strategies/AbstractFetchStrategy.ts:190

Parameters

url

undefined | string

Returns

void

Inherited from

PostsArchiveFetchStrategy.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

Inherited from

PostsArchiveFetchStrategy.setEndpoint