Service for retrieving content categories and their hierarchical structure.

Accessible via lynkow.categories. Categories organize blog articles and can be nested (parent/child). Each category includes a content count and optional image. Responses are cached for 5 minutes (SHORT TTL) when a cache adapter is configured.

Access via: lynkow.categories

Methods

4 methods

clearCache

TypeScript
clearCache(): void

Invalidates all cached category responses (lists, tree, and detail views). Call this after knowing categories have been updated to force fresh data on the next request.

Returns: void


getBySlug

TypeScript
getBySlug(slug: string, options?: CategoryOptions & BaseRequestOptions): Promise<CategoryDetailResponse>

Retrieves a single category by its slug, along with a paginated list of the published articles that belong to it. Cached for 5 minutes per slug+locale+pagination combination.

Parameter

Type

Description

slug

string

The unique URL slug of the category (e.g. 'tech', 'news', 'tutorials')

options

CategoryOptions & BaseRequestOptions

Combined category and request options:<br> - page / limit — pagination for the category's articles (defaults to page 1)<br> - locale — override the client's default locale

Returns: Promise<CategoryDetailResponse>

TypeScript
const { category, contents } = await lynkow.categories.getBySlug('tech', {
  page: 1,
  limit: 10
})
console.log(category.name)             // "Tech"
console.log(contents.data.length)      // Number of articles on this page
console.log(contents.meta.hasMorePages) // Whether more pages exist

list

TypeScript
list(options?: BaseRequestOptions): Promise<CategoriesListResponse>

Retrieves a flat list of all categories with their content counts. Useful for building navigation menus, sidebars, or category filters. Cached for 5 minutes per locale.

Parameter

Type

Description

options

BaseRequestOptions

Request options; use locale to fetch localized category names

Returns: Promise<CategoriesListResponse>

TypeScript
const { data, blogUrlMode } = await lynkow.categories.list()
data.forEach(cat => {
  console.log(`${cat.name} (${cat.contentCount} articles)`)
})

tree

TypeScript
tree(options?: BaseRequestOptions): Promise<CategoryTreeResponse>

Retrieves the full category hierarchy as a nested tree structure. Root categories appear at the top level, each with a children array containing their subcategories (recursively). Useful for building hierarchical navigation or breadcrumbs. Cached for 5 minutes per locale.

Parameter

Type

Description

options

BaseRequestOptions

Request options; use locale to fetch localized category names

Returns: Promise<CategoryTreeResponse>

TypeScript
const { data } = await lynkow.categories.tree()
// Iterate root categories and their children
data.forEach(root => {
  console.log(root.name)
  root.children.forEach(child => {
    console.log(`  - ${child.name}`)
  })
})