blob: e61c7e7fd72cf88824d744506086054b81a91e73 [file] [log] [blame]
= Wordpress Component
:doctitle: Wordpress
:shortname: wordpress
:artifactid: camel-wordpress
:description: Manage posts and users using Wordpress API.
:since: 2.21
:supportlevel: Stable
:tabs-sync-option:
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:camel-spring-boot-name: wordpress
*Since Camel {since}*
*{component-header}*
Camel component for https://developer.wordpress.org/rest-api/reference/[Wordpress API].
Currently only the **Posts** and **Users** operations are supported.
// component-configure options: START
// component-configure options: END
// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END
// endpoint options: START
// endpoint options: END
Most of parameters needed when performing a read operation mirrors from the official https://developer.wordpress.org/rest-api/reference/[API]. When performing searches operations, the `criteria.` suffix is needed. Take the following `Consumer` as example:
----
wordpress:post?criteria.perPage=10&criteria.orderBy=author&criteria.categories=camel,dozer,json
----
== Configuring Wordpress component
The `WordpressConfiguration` class can be used to set initial properties configuration to the component instead of passing it as query parameter. The following listing shows how to set the component to be used in your routes.
[source,java]
----
public void configure() {
final WordpressConfiguration configuration = new WordpressConfiguration();
final WordpressComponent component = new WordpressComponent();
configuration.setApiVersion("2");
configuration.setUrl("http://yoursite.com/wp-json/");
component.setConfiguration(configuration);
getContext().addComponent("wordpress", component);
from("wordpress:post?id=1")
.to("mock:result");
}
----
== Consumer Example
Consumer polls from the API from time to time domain objects from Wordpress. Following, an example using the `Post` operation:
- `wordpress:post` retrieves posts (defaults to 10 posts)
- `wordpress:post?id=1` search for a specific post
== Producer Example
Producer performs write operations on Wordpress like adding a new user or update a post. To be able to write, you must have an authorized user credentials (see Authentication).
- `wordpress:post` creates a new post from the `org.apache.camel.component.wordpress.api.model.Post` class in the message body.
- `wordpress:post?id=1` updates a post based on data `org.apache.camel.component.wordpress.api.model.Post` from the message body.
- `wordpress:post:delete?id=1` deletes a specific post
== Authentication
Producers that perform write operations (e.g. create a new post) https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/[must have an authenticated user] to do so. The standard authentication mechanism used by Wordpress is cookie. Unfortunately this method is not supported outside Wordpress environment because it's rely on https://codex.wordpress.org/WordPress_Nonces[nonce] internal function.
There's some alternatives to use the Wordpress API without nonces, but requires specific plugin installations.
At this time, `camel-wordpress` only supports Basic Authentication (more to come). To configure it, you must install the https://github.com/WP-API/Basic-Auth[Basic-Auth Wordpress plugin] and pass the credentials to the endpoint:
`from("direct:deletePost").to("wordpress:post:delete?id=9&user=ben&password=password123").to("mock:resultDelete");`
**It's not recommend to use Basic Authentication in production without TLS!!**
include::spring-boot:partial$starter.adoc[]