Interface PostOperations

All Known Subinterfaces:
WpRestClient
All Known Implementing Classes:
ApacheWpRestClient, WpBaseRestClient

public interface PostOperations
Defines operations for managing WordPress posts through the WordPress REST API.

This interface provides methods for creating, retrieving, updating, listing, trashing, and deleting WpPost resources.

Operations support standard WordPress REST API features such as pagination, filtering, retrieval contexts, password-protected content, and partial querying.

Implementations are expected to communicate with the /wp-json/wp/v2/posts endpoint or compatible APIs.

  • Method Details

    • createPost

      WpPost createPost(@NonNull @NonNull WpPostCreateUpdateRequest creationRequest)
      Creates a new post.

      Creates a post in WordPress using the provided request payload.

      Parameters:
      creationRequest - the post creation request; must not be null
      Returns:
      the created WpPost
    • deletePost

      WpPostDeletionResponse deletePost(@NonNull @NonNull Long id)
      Permanently deletes a post by its unique identifier.
      Parameters:
      id - the ID of the post to delete; must not be null
      Returns:
      the post deletion response
    • getPost

      WpPost getPost(@NonNull @NonNull Long id, WpContext context)
      Retrieves a post by its unique identifier using the given context.

      The context determines which fields are included in the response, for example WpContext.VIEW, WpContext.EDIT, or WpContext.EMBED.

      Parameters:
      id - the ID of the post to retrieve; must not be null
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpPost
    • getPost

      WpPost getPost(@NonNull @NonNull Long id, WpContext context, String password)
      Retrieves a post by its unique identifier using the given context and optional password.

      The context determines which fields are included in the response, for example WpContext.VIEW, WpContext.EDIT, or WpContext.EMBED.

      If the post is password protected, the provided password is used to access protected content. If the password is missing or incorrect, protected fields such as content or excerpt may be omitted or flagged as protected in the response.

      Parameters:
      id - the ID of the post to retrieve; must not be null
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      password - the password for protected content; may be null when not required
      Returns:
      the matching WpPost
    • listPosts

      WpPagedResponse<WpPost> listPosts(@NonNull @NonNull WpPagingQuery pageQuery, WpPostQuery postQuery)
      Retrieves a paginated list of posts using optional filtering and sorting criteria.

      The result set can be refined using WpPostQuery, for example by filtering on search criteria, include or exclude lists, or sort order.

      Parameters:
      pageQuery - the pagination settings, including page number and page size; must not be null
      postQuery - additional post query parameters; may be null when no extra filtering is needed
      Returns:
      a paginated response containing WpPost items
    • trashPost

      WpPost trashPost(@NonNull @NonNull Long id)
      Moves a post to the trash by its unique identifier.
      Parameters:
      id - the ID of the post to trash; must not be null
      Returns:
      the trashed WpPost
    • updatePost

      WpPost updatePost(@NonNull @NonNull Long id, @NonNull @NonNull WpPostCreateUpdateRequest updateRequest)
      Updates an existing post.

      Updates a post in WordPress using the provided request payload.

      Parameters:
      id - the ID of the post to update; must not be null
      updateRequest - the post update request; must not be null
      Returns:
      the updated WpPost