Class ApacheWpRestClient
- All Implemented Interfaces:
CategoryOperations,CommentOperations,MediaOperations,PostOperations,PostTypesOperations,StatusOperations,TagOperations,WpRestClient
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:
- Authentication (
AuthenticationInterceptor) - WordPress-specific error handling (
WpErrorInterceptor)
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 Summary
Modifier and TypeMethodDescriptioncreateCategory(@NonNull WpCategoryCreateUpdateRequest creationRequest) Creates a new category.createComment(@NonNull WpCommentCreateUpdateRequest creationRequest) Creates a new comment.createMedia(@NonNull File file, @NonNull String fileName, @NonNull String mimeType) Creates a new media item.createPost(@NonNull WpPostCreateUpdateRequest creationRequest) Creates a new post.createTag(@NonNull WpTagCreateUpdateRequest creationRequest) Creates a new tag.deleteCategory(long id) Deletes a category by its unique identifier.deleteComment(long id) Permanently deletes a comment by its unique identifier.deleteMedia(long id) Deletes a media item by its unique identifier.deletePost(long id) Permanently deletes a post by its unique identifier.deleteTag(long id) Deletes a tag by its unique identifier.getCategory(long id, WpContext context) Retrieves a category by its unique identifier using the given context.getComment(long id, WpContext context) Retrieves a comment by its unique identifier using the given context.getComment(long id, WpContext context, String password) Retrieves a comment by its unique identifier using the given context and optional password.Retrieves a media item by its unique identifier using the given context.Retrieves a post by its unique identifier using the given context.Retrieves a post by its unique identifier using the given context and optional password.getPostType(@NonNull String name) Retrieves a post type definition by its unique name.Retrieves all registered post types.Retrieves a post status definition by its unique slug.Retrieves all registered post statuses.Retrieves a tag by its unique identifier using the given context.listCategories(@NonNull WpPagingQuery pageQuery, WpCategoryQuery categoryQuery) Retrieves a paginated list of categories using optional filtering and sorting criteria.listComments(@NonNull WpPagingQuery pageQuery, WpCommentQuery commentQuery) Retrieves a paginated list of comments using optional filtering and sorting criteria.listMedia(@NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery) Retrieves a paginated list of media items using optional filtering and sorting criteria.listPosts(@NonNull WpPagingQuery pageQuery, WpPostQuery postQuery) Retrieves a paginated list of posts using optional filtering and sorting criteria.listTags(@NonNull WpPagingQuery pageQuery, WpTagQuery tagQuery) Retrieves a paginated list of tags using optional filtering and sorting criteria.trashComment(long id) Moves a comment to the trash by its unique identifier.trashPost(long id) Moves a post to the trash by its unique identifier.updateCategory(long id, @NonNull WpCategoryCreateUpdateRequest updateRequest) Updates an existing category.updateComment(long id, @NonNull WpCommentCreateUpdateRequest updateRequest) Updates an existing comment.updateMedia(long id, @NonNull WpMediaUpdateRequest updateRequest) Updates an existing media item.updatePost(long id, @NonNull WpPostCreateUpdateRequest updateRequest) Updates an existing post.updateTag(long id, @NonNull WpTagCreateUpdateRequest updateRequest) Updates an existing tag.
-
Method Details
-
createCategory
Description copied from interface:CategoryOperationsCreates a new category.Creates a category in WordPress using the provided request payload.
- Parameters:
creationRequest- the category creation request; must not benull- Returns:
- the created
WpCategory
-
createComment
Description copied from interface:CommentOperationsCreates a new comment.Creates a comment in WordPress using the provided request payload.
- Parameters:
creationRequest- the comment creation request; must not benull- Returns:
- the created
WpComment
-
createMedia
public WpMedia createMedia(@NonNull @NonNull File file, @NonNull @NonNull String fileName, @NonNull @NonNull String mimeType) Description copied from interface:MediaOperationsCreates 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
WpMediaattachment resource.- Parameters:
file- the file to upload; must not benullfileName- the filename to associate with the uploaded media item; must not benullmimeType- the MIME type of the uploaded file, for exampleimage/png; must not benull- Returns:
- the created
WpMedia
-
createPost
Description copied from interface:PostOperationsCreates a new post.Creates a post in WordPress using the provided request payload.
- Parameters:
creationRequest- the post creation request; must not benull- Returns:
- the created
WpPost
-
createTag
Description copied from interface:TagOperationsCreates a new tag.Creates a tag in WordPress using the provided request payload.
- Parameters:
creationRequest- the tag creation request; must not benull- Returns:
- the created
WpTag
-
deleteCategory
Description copied from interface:CategoryOperationsDeletes a category by its unique identifier.- Parameters:
id- the ID of the category to delete- Returns:
- the category deletion response
-
deleteComment
Description copied from interface:CommentOperationsPermanently deletes a comment by its unique identifier.- Parameters:
id- the ID of the comment to delete- Returns:
- the comment deletion response
-
deleteMedia
Description copied from interface:MediaOperationsDeletes a media item by its unique identifier.- Parameters:
id- the ID of the media item to delete- Returns:
- the media item deletion response
-
deletePost
Description copied from interface:PostOperationsPermanently deletes a post by its unique identifier.- Parameters:
id- the ID of the post to delete- Returns:
- the post deletion response
-
deleteTag
Description copied from interface:TagOperationsDeletes a tag by its unique identifier.- Parameters:
id- the ID of the tag to delete- Returns:
- the tag deletion response
-
getCategory
Description copied from interface:CategoryOperationsRetrieves 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, orWpContext.EMBED.- Parameters:
id- the ID of the category to retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis used- Returns:
- the matching
WpCategory
-
getComment
Description copied from interface:CommentOperationsRetrieves 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, orWpContext.EMBED.- Parameters:
id- the ID of the comment to retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis used- Returns:
- the matching
WpComment
-
getComment
Description copied from interface:CommentOperationsRetrieves 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, orWpContext.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 retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis usedpassword- the password for protected content; may benullwhen not required- Returns:
- the matching
WpComment
-
getMedia
Description copied from interface:MediaOperationsRetrieves 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, orWpContext.EMBED.- Parameters:
id- the ID of the media item to retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis used- Returns:
- the matching
WpMedia
-
getPost
Description copied from interface:PostOperationsRetrieves 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, orWpContext.EMBED.- Parameters:
id- the ID of the post to retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis used- Returns:
- the matching
WpPost
-
getPost
Description copied from interface:PostOperationsRetrieves 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, orWpContext.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 retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis usedpassword- the password for protected content; may benullwhen not required- Returns:
- the matching
WpPost
-
getPostType
Description copied from interface:PostTypesOperationsRetrieves 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 benull- Returns:
- the matching
WpPostType
-
getPostTypes
Description copied from interface:PostTypesOperationsRetrieves all registered post types.The returned map is keyed by post type name and contains the corresponding
WpPostTypedefinitions.- Returns:
- a map of post type names to post type definitions
-
getStatus
Description copied from interface:StatusOperationsRetrieves a post status definition by its unique slug.Examples include
publish,draft,pending,future, andprivate.- Parameters:
name- the status slug; must not benull- Returns:
- the matching
WpStatus
-
getStatuses
Description copied from interface:StatusOperationsRetrieves all registered post statuses.The returned map is keyed by status slug and contains the corresponding
WpStatusdefinitions.- Returns:
- a map of status slugs to status definitions
-
getTag
Description copied from interface:TagOperationsRetrieves 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, orWpContext.EMBED.- Parameters:
id- the ID of the tag to retrievecontext- the retrieval context; may benull, in which caseWpContext.VIEWis used- Returns:
- the matching
WpTag
-
listCategories
public WpPagedResponse<WpCategory> listCategories(@NonNull @NonNull WpPagingQuery pageQuery, WpCategoryQuery categoryQuery) Description copied from interface:CategoryOperationsRetrieves 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 benullcategoryQuery- additional category query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpCategoryitems
-
listComments
public WpPagedResponse<WpComment> listComments(@NonNull @NonNull WpPagingQuery pageQuery, WpCommentQuery commentQuery) Description copied from interface:CommentOperationsRetrieves 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 benullcommentQuery- additional comment query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpCommentitems
-
listMedia
public WpPagedResponse<WpMedia> listMedia(@NonNull @NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery) Description copied from interface:MediaOperationsRetrieves 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 benullmediaQuery- additional media query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpMediaitems
-
listPosts
public WpPagedResponse<WpPost> listPosts(@NonNull @NonNull WpPagingQuery pageQuery, WpPostQuery postQuery) Description copied from interface:PostOperationsRetrieves 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 benullpostQuery- additional post query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpPostitems
-
listTags
public WpPagedResponse<WpTag> listTags(@NonNull @NonNull WpPagingQuery pageQuery, WpTagQuery tagQuery) Description copied from interface:TagOperationsRetrieves 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 benulltagQuery- additional tag query parameters; may benullwhen no extra filtering is needed- Returns:
- a paginated response containing
WpTagitems
-
trashComment
Description copied from interface:CommentOperationsMoves a comment to the trash by its unique identifier.- Parameters:
id- the ID of the comment to trash- Returns:
- the trashed
WpComment
-
trashPost
Description copied from interface:PostOperationsMoves 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:CategoryOperationsUpdates an existing category.Updates a category in WordPress using the provided request payload.
- Parameters:
id- the ID of the category to updateupdateRequest- the category update request; must not benull- Returns:
- the updated
WpCategory
-
updateComment
public WpComment updateComment(long id, @NonNull @NonNull WpCommentCreateUpdateRequest updateRequest) Description copied from interface:CommentOperationsUpdates an existing comment.Updates a comment in WordPress using the provided request payload.
- Parameters:
id- the ID of the comment to updateupdateRequest- the post update request; must not benull- Returns:
- the updated
WpComment
-
updateMedia
Description copied from interface:MediaOperationsUpdates an existing media item.Updates a media item in WordPress using the provided request payload.
- Parameters:
id- the ID of the media item to updateupdateRequest- the category update request; must not benull- Returns:
- the updated
WpMedia
-
updatePost
Description copied from interface:PostOperationsUpdates an existing post.Updates a post in WordPress using the provided request payload.
- Parameters:
id- the ID of the post to updateupdateRequest- the post update request; must not benull- Returns:
- the updated
WpPost
-
updateTag
Description copied from interface:TagOperationsUpdates an existing tag.Updates a tag in WordPress using the provided request payload.
- Parameters:
id- the ID of the tag to updateupdateRequest- the tag update request; must not benull- Returns:
- the updated
WpTag
-