Class ApacheWpRestClient

java.lang.Object
io.github.evisentin.wordpress.client.domain.api.WpBaseRestClient
io.github.evisentin.wordpress.client.adapter.apache.ApacheWpRestClient
All Implemented Interfaces:
CategoryOperations, CommentOperations, MediaOperations, PostOperations, PostTypesOperations, StatusOperations, TagOperations, WpRestClient

public class ApacheWpRestClient extends WpBaseRestClient
Apache HttpClient-based implementation of WpBaseRestClient.

This client provides a synchronous wrapper around the WordPress REST API using CloseableHttpClient as the underlying HTTP transport.

It supports CRUD operations and paginated queries for core WordPress resources such as posts, categories, and tags.

The client is configured with an authentication strategy and automatically registers internal interceptors for:

Optional SslConfiguration and TimeoutConfiguration can be provided to customize TLS behaviour, connection management, and request timeouts. Thread Safety

Instances of this class are thread-safe and intended to be reused.

See Also:
  • Method Details

    • createCategory

      public WpCategory createCategory(@NonNull @NonNull WpCategoryCreateUpdateRequest creationRequest)
      Description copied from interface: CategoryOperations
      Creates a new category.

      Creates a category in WordPress using the provided request payload.

      Parameters:
      creationRequest - the category creation request; must not be null
      Returns:
      the created WpCategory
    • createComment

      public WpComment createComment(@NonNull @NonNull WpCommentCreateUpdateRequest creationRequest)
      Description copied from interface: CommentOperations
      Creates a new comment.

      Creates a comment in WordPress using the provided request payload.

      Parameters:
      creationRequest - the comment creation request; must not be null
      Returns:
      the created WpComment
    • createMedia

      public WpMedia createMedia(@NonNull @NonNull File file, @NonNull @NonNull String fileName, @NonNull @NonNull String mimeType)
      Description copied from interface: MediaOperations
      Creates a new media item.

      Uploads a media file to WordPress using the provided file content and metadata.

      The uploaded file is sent to the WordPress media endpoint and results in the creation of a new WpMedia attachment resource.

      Parameters:
      file - the file to upload; must not be null
      fileName - the filename to associate with the uploaded media item; must not be null
      mimeType - the MIME type of the uploaded file, for example image/png; must not be null
      Returns:
      the created WpMedia
    • createPost

      public WpPost createPost(@NonNull @NonNull WpPostCreateUpdateRequest creationRequest)
      Description copied from interface: PostOperations
      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
    • createTag

      public WpTag createTag(@NonNull @NonNull WpTagCreateUpdateRequest creationRequest)
      Description copied from interface: TagOperations
      Creates a new tag.

      Creates a tag in WordPress using the provided request payload.

      Parameters:
      creationRequest - the tag creation request; must not be null
      Returns:
      the created WpTag
    • deleteCategory

      public WpCategoryDeletionResponse deleteCategory(long id)
      Description copied from interface: CategoryOperations
      Deletes a category by its unique identifier.
      Parameters:
      id - the ID of the category to delete
      Returns:
      the category deletion response
    • deleteComment

      public WpCommentDeletionResponse deleteComment(long id)
      Description copied from interface: CommentOperations
      Permanently deletes a comment by its unique identifier.
      Parameters:
      id - the ID of the comment to delete
      Returns:
      the comment deletion response
    • deleteMedia

      public WpMediaDeletionResponse deleteMedia(long id)
      Description copied from interface: MediaOperations
      Deletes a media item by its unique identifier.
      Parameters:
      id - the ID of the media item to delete
      Returns:
      the media item deletion response
    • deletePost

      public WpPostDeletionResponse deletePost(long id)
      Description copied from interface: PostOperations
      Permanently deletes a post by its unique identifier.
      Parameters:
      id - the ID of the post to delete
      Returns:
      the post deletion response
    • deleteTag

      public WpTagDeletionResponse deleteTag(long id)
      Description copied from interface: TagOperations
      Deletes a tag by its unique identifier.
      Parameters:
      id - the ID of the tag to delete
      Returns:
      the tag deletion response
    • getCategory

      public WpCategory getCategory(long id, WpContext context)
      Description copied from interface: CategoryOperations
      Retrieves a category 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 category to retrieve
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpCategory
    • getComment

      public WpComment getComment(long id, WpContext context)
      Description copied from interface: CommentOperations
      Retrieves a comment 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 comment to retrieve
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpComment
    • getComment

      public WpComment getComment(long id, WpContext context, String password)
      Description copied from interface: CommentOperations
      Retrieves a comment 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 comment is password protected, the provided password is used to access protected content. If the password is missing or incorrect, protected fields such as content may be omitted or flagged as protected in the response.

      Parameters:
      id - the ID of the comment to retrieve
      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 WpComment
    • getMedia

      public WpMedia getMedia(long id, WpContext context)
      Description copied from interface: MediaOperations
      Retrieves a media item 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 media item to retrieve
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpMedia
    • getPost

      public WpPost getPost(long id, WpContext context)
      Description copied from interface: PostOperations
      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
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpPost
    • getPost

      public WpPost getPost(long id, WpContext context, String password)
      Description copied from interface: PostOperations
      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
      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
    • getPostType

      public WpPostType getPostType(@NonNull @NonNull String name)
      Description copied from interface: PostTypesOperations
      Retrieves a post type definition by its unique name.

      Examples include post, page, attachment, and custom post type names registered by plugins or themes.

      Parameters:
      name - the post type name; must not be null
      Returns:
      the matching WpPostType
    • getPostTypes

      public Map<String,WpPostType> getPostTypes()
      Description copied from interface: PostTypesOperations
      Retrieves all registered post types.

      The returned map is keyed by post type name and contains the corresponding WpPostType definitions.

      Returns:
      a map of post type names to post type definitions
    • getStatus

      public WpStatus getStatus(@NonNull @NonNull String name)
      Description copied from interface: StatusOperations
      Retrieves a post status definition by its unique slug.

      Examples include publish, draft, pending, future, and private.

      Parameters:
      name - the status slug; must not be null
      Returns:
      the matching WpStatus
    • getStatuses

      public Map<String,WpStatus> getStatuses()
      Description copied from interface: StatusOperations
      Retrieves all registered post statuses.

      The returned map is keyed by status slug and contains the corresponding WpStatus definitions.

      Returns:
      a map of status slugs to status definitions
    • getTag

      public WpTag getTag(long id, WpContext context)
      Description copied from interface: TagOperations
      Retrieves a tag 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 tag to retrieve
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpTag
    • listCategories

      public WpPagedResponse<WpCategory> listCategories(@NonNull @NonNull WpPagingQuery pageQuery, WpCategoryQuery categoryQuery)
      Description copied from interface: CategoryOperations
      Retrieves a paginated list of categories using optional filtering and sorting criteria.

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

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

      public WpPagedResponse<WpComment> listComments(@NonNull @NonNull WpPagingQuery pageQuery, WpCommentQuery commentQuery)
      Description copied from interface: CommentOperations
      Retrieves a paginated list of comments using optional filtering and sorting criteria.

      The result set can be refined using WpCommentQuery, 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
      commentQuery - additional comment query parameters; may be null when no extra filtering is needed
      Returns:
      a paginated response containing WpComment items
    • listMedia

      public WpPagedResponse<WpMedia> listMedia(@NonNull @NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery)
      Description copied from interface: MediaOperations
      Retrieves a paginated list of media items using optional filtering and sorting criteria.

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

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

      public WpPagedResponse<WpPost> listPosts(@NonNull @NonNull WpPagingQuery pageQuery, WpPostQuery postQuery)
      Description copied from interface: PostOperations
      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
    • listTags

      public WpPagedResponse<WpTag> listTags(@NonNull @NonNull WpPagingQuery pageQuery, WpTagQuery tagQuery)
      Description copied from interface: TagOperations
      Retrieves a paginated list of tags using optional filtering and sorting criteria.

      The result set can be refined using WpTagQuery, 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
      tagQuery - additional tag query parameters; may be null when no extra filtering is needed
      Returns:
      a paginated response containing WpTag items
    • trashComment

      public WpComment trashComment(long id)
      Description copied from interface: CommentOperations
      Moves a comment to the trash by its unique identifier.
      Parameters:
      id - the ID of the comment to trash
      Returns:
      the trashed WpComment
    • trashPost

      public WpPost trashPost(long id)
      Description copied from interface: PostOperations
      Moves a post to the trash by its unique identifier.
      Parameters:
      id - the ID of the post to trash
      Returns:
      the trashed WpPost
    • updateCategory

      public WpCategory updateCategory(long id, @NonNull @NonNull WpCategoryCreateUpdateRequest updateRequest)
      Description copied from interface: CategoryOperations
      Updates an existing category.

      Updates a category in WordPress using the provided request payload.

      Parameters:
      id - the ID of the category to update
      updateRequest - the category update request; must not be null
      Returns:
      the updated WpCategory
    • updateComment

      public WpComment updateComment(long id, @NonNull @NonNull WpCommentCreateUpdateRequest updateRequest)
      Description copied from interface: CommentOperations
      Updates an existing comment.

      Updates a comment in WordPress using the provided request payload.

      Parameters:
      id - the ID of the comment to update
      updateRequest - the post update request; must not be null
      Returns:
      the updated WpComment
    • updateMedia

      public WpMedia updateMedia(long id, @NonNull @NonNull WpMediaUpdateRequest updateRequest)
      Description copied from interface: MediaOperations
      Updates an existing media item.

      Updates a media item in WordPress using the provided request payload.

      Parameters:
      id - the ID of the media item to update
      updateRequest - the category update request; must not be null
      Returns:
      the updated WpMedia
    • updatePost

      public WpPost updatePost(long id, @NonNull @NonNull WpPostCreateUpdateRequest updateRequest)
      Description copied from interface: PostOperations
      Updates an existing post.

      Updates a post in WordPress using the provided request payload.

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

      public WpTag updateTag(long id, @NonNull @NonNull WpTagCreateUpdateRequest updateRequest)
      Description copied from interface: TagOperations
      Updates an existing tag.

      Updates a tag in WordPress using the provided request payload.

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