All Projects → Afrozaar → wp-api-v2-client-java

Afrozaar / wp-api-v2-client-java

Licence: Apache-2.0 license
WP-API v2 Java Client

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to wp-api-v2-client-java

unleash-client-java
Unleash client SDK for Java
Stars: ✭ 86 (+19.44%)
Mutual labels:  java-client
kong-java-client
Java Client for Kong API Gateway configuration
Stars: ✭ 69 (-4.17%)
Mutual labels:  java-client
SketchwareAPI
Sketchware API Multiplatform Library
Stars: ✭ 26 (-63.89%)
Mutual labels:  java-client
cassandra-client
Cassandra 3 GUI client
Stars: ✭ 49 (-31.94%)
Mutual labels:  java-client
cerberus-java-client
Java Client for Cerberus
Stars: ✭ 14 (-80.56%)
Mutual labels:  java-client
itunes-api
Java client for iTunes APIs
Stars: ✭ 32 (-55.56%)
Mutual labels:  java-client
JRediSearch
Java Client for RediSearch
Stars: ✭ 133 (+84.72%)
Mutual labels:  java-client
SparkJobServerClient
Java Client of the Spark Job Server implementing the arranged Rest APIs
Stars: ✭ 50 (-30.56%)
Mutual labels:  java-client
jetty-load-generator
jetty-project.github.io/jetty-load-generator/
Stars: ✭ 62 (-13.89%)
Mutual labels:  java-client
JRedisGraph
Java API for RedisGraph
Stars: ✭ 56 (-22.22%)
Mutual labels:  java-client
JRedisTimeSeries
Java Client for RedisTimeSeries
Stars: ✭ 29 (-59.72%)
Mutual labels:  java-client
Kubernetes Client
Java client for Kubernetes & OpenShift
Stars: ✭ 2,188 (+2938.89%)
Mutual labels:  java-client
Mockserver
MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and…
Stars: ✭ 3,479 (+4731.94%)
Mutual labels:  java-client
onesait-cloud-platform-clientlibraries
Client libraries to interact with Onesait Platform Cloud Side (Digital Broker specially)
Stars: ✭ 15 (-79.17%)
Mutual labels:  java-client
mockserver-node
Node.js module and grunt plugin to start and stop MockServer and MockServer Proxy
Stars: ✭ 34 (-52.78%)
Mutual labels:  java-client
nakama-java
Android optimized Java client for Nakama server.
Stars: ✭ 26 (-63.89%)
Mutual labels:  java-client
grafana-api-java-client
A simple java client for interacting with Grafana using a fluent interface.
Stars: ✭ 40 (-44.44%)
Mutual labels:  java-client
redis-modules-java
Java client libraries for redis-modules https://redis.io/modules, based on Redisson. https://github.com/redisson/redisson
Stars: ✭ 57 (-20.83%)
Mutual labels:  java-client

LOOKING FOR A MAINTAINER

Codeship Status for Afrozaar/wp-api-v2-client-java

WP-API v2 Java Client

A Java client to version 2 of the WP REST API, recently merged into WordPress Core

(Currently coding against WordPress 4.8.x)

WordPress Supported Versions

The current 4.8 version supports WordPress 4.6-4.8.

See

Current Development Requirements

  • WordPress 4.8.0+ installation
  • JSON Basic Authentication (0.1 currently used)

Implemented

  • Posts CRUD
  • Post Meta CRUD
  • Terms CRUD
  • Taxonomy CRUD
  • Post Terms CRUD
  • Pages CRUD
  • Users

Work In Progress

...

Not Yet Implemented

  • Post Revisions
  • Post Types
  • Post Statuses
  • Comments

Basic Usage

Instantiating and using a new client

String baseUrl = "http://myhost";
String username = "myUsename";
String password = "myPassword";
boolean debug = false;

final Wordpress client = ClientFactory.fromConfig(ClientConfig.of(baseUrl, username, password, debug));

Creating a new post

final Post post = PostBuilder.aPost()
    .withTitle(TitleBuilder.aTitle().withRendered(expectedTitle).build())
    .withExcerpt(ExcerptBuilder.anExcerpt().withRendered(expectedExcerpt).build())
    .withContent(ContentBuilder.aContent().withRendered(expectedContent).build())
    .build();

final Post createdPost = client.createPost(post, PostStatus.publish);

Searching Posts

Search Posts not having a particular Meta Key

Sample Code

final PagedResponse<Post> response = client.search(SearchRequest.Builder.aSearchRequest(Post.class)
        .withUri(Request.POSTS)
        .withParam("filter[meta_key]", "baobab_indexed")
        .withParam("filter[meta_compare]", "NOT EXISTS") //RestTemplate takes care of escaping values ('space' -> '%20')
        .build());                

Equivalent Curl/httpie Request

$ http --auth 'username:password' http://myhost/wp-json/wp/v2/posts?filter[meta_key]=baobab_indexed&filter[meta_compare]=NOT%20EXISTS

Search types

The client is flexible enough to build search requests of a particular type, if that type supports filtering.

final PagedResponse<Media> tagResults = client.search(SearchRequest.Builder.aSearchRequest(Media.class)
    .withUri("/media")
    .withParam("filter[s]", "searchTerm")
    .build());

Available Filters

More Usage Examples

Advanced/Restricted Filtering

For advanced filtering in a particular use case, it is required to search for posts not having a particular custom field. In order to search for such posts, the standard filter keys are not sufficient, and needs to be enabled by allowing more keys.

Do note that the effect of this change is only visible when an authenticated call is made, as per the WP-API documentation.

A snippet containing the keys that you wish to use needs to be added to either your theme's functions.php file, or WP-API's plugin.php:

function my_allow_meta_query( $valid_vars ) {

        $valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_compare' ) );
        return $valid_vars;
}
add_filter( 'rest_query_vars', 'my_allow_meta_query' );

Controlling HTTP Connection behavior

If needed, org.springframework.http.client.ClientHttpRequestFactory can be provided to control the HTTP connection behavior. Below example shows how to disable SSL verification when invoking https wordpress endpoints.

	TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

	SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
	        .loadTrustMaterial(null, acceptingTrustStrategy)
	        .build();

	SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

	CloseableHttpClient httpClient = HttpClients.custom()
	        .setSSLSocketFactory(csf)
	        .build();

	HttpComponentsClientHttpRequestFactory requestFactory =
	        new HttpComponentsClientHttpRequestFactory();

	requestFactory.setHttpClient(httpClient);

	boolean debug = false;

	final Wordpress wordpress = ClientFactory.builder(ClientConfig.of(httpBaseURL, username, password, debug))
            .withRequestFactory(requestFactory)
            .build();

TODO

  • Add support for authentication providers such as OAuth. (Currently only basic authentication is used)

Testing

Live Testing

These tests are intended to run against a live WordPress installation.

For convenience, a wordpress docker has been created. This docker has a pre-installed-and-set-up wordpress instance, with the latest (beta9) version of rest-api and JSON Basic Auth plugins enabled. Configuration has already been included in the test configuration directory.

To make use of this docker, you can do the following:

docker run -d --name wp_build_test -p 80:80 afrozaar/wordpress:latest

More configuration is required (adding an entry to your hosts file), so see Afrozaar/docker-wordpress on GitHub.

Configuration

To run against your local wordpress installation, it is required to have a YAML configuration file available at: ${project}/src/test/resources/config/${hostname}-test.yaml with the following structure:

wordpress:
  username: "myUsername"
  password: "myPassword"
  baseUrl: "http://myhost"
  usePermalinkEndpoint: false

debug: "true"

This configuration must not be included in version control. *.yaml is already included in the .gitignore file.

Please ensure that you do not commit hard-coded environment information.

Maven

Latest snapshot is available from our public maven repository at

Release versions should also be available on public maven repositories:

<dependency>
  <groupId>com.afrozaar.wordpress</groupId>
  <artifactId>wp-api-v2-client-java</artifactId>
  <version>4.8.1</version>
</dependency>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].