Skip to content

Interfaces and Extensions

Arun Prakash edited this page Sep 21, 2025 · 3 revisions

🧩 Interfaces & Extensions

wordpress_client keeps the core API focused by exposing typed request classes and optional convenience extensions.

Core pattern

  • Each resource is represented by an interface (e.g., PostsInterface)
  • Requests are explicit: ListPostRequest, RetrievePostRequest, CreatePostRequest, etc.
  • Interfaces mix in operations: ListOperation<T, R>, RetrieveOperation<T, R>, CreateOperation<T, R>, UpdateOperation<T, R>, DeleteOperation<R>

Using interfaces directly

final res = await client.posts.list(ListPostRequest(perPage: 20));
final posts = res.asSuccess().data;

Convenience extensions

To keep call sites concise, many interfaces provide an extensions helper with common shortcuts.

final post = await client.posts.extensions.getById(123);
final slug = await client.posts.extensions.findBySlug('hello-world');
final all  = await client.posts.extensions.listAll(perPage: 50);

Extensions exist for: Posts, Pages, Media, Users, Categories, Tags, Comments, Blocks, Block Types, Templates, Template Parts, Template/Part Revisions, Navigations, Navigation Revisions/Autosaves, Menus, Menu Items, Menu Locations, Widgets, Sidebars, Widget Types, Post Types, Taxonomies, Post Statuses, Themes, Global Styles, Post/Page Revisions, and Settings.

Pro tip: Extensions are just thin wrappers around the typed requestsβ€”mix them with explicit requests as needed.

🌊 Fluent Queries on Interfaces

Every major interface surfaces a query property that returns a fluent builder. It auto‑seeds the correct list request type and exposes common helpers:

final res = await client.posts.query
	.withPage(1)
	.withPerPage(10)
	.withSearch('welcome')
	.execute();

Advanced users can mutate the underlying seed via:

final res2 = await client.posts.query
	.configureSeed((seed) { seed.context = RequestContext.view; })
	.execute();

See also: Usage β€Ί Fluent Queries

Clone this wiki locally