washingtonpost/wordpress-rest-api-java-client

Name: wordpress-rest-api-java-client

Owner: The Washington Post

Description: Java Client for connecting to and parsing JSON coming our of a WordPress REST API plugin

Created: 2015-08-19 14:23:11.0

Updated: 2018-01-07 07:32:19.0

Pushed: 2015-08-26 15:51:12.0

Homepage: null

Size: 260

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

wordpress-rest-api-java-client

Java Client for connecting to and parsing JSON coming our of a WordPress REST API plugin

This Client uses JAX-RS to connect to a remote WordPress REST API and retrieve the lists of Posts from the /posts endpoint. The client passes through whatever query parameters sent to the getPosts( ) method directly to the WordPress REST API. This client comes with a default implementation of a Transformer class that knows how to transform WordPress JSON into a “WordPressPost.java” POJO.

If your WordPress JSON feed is customized to include fields not contained in the off-the-shelf WordPress JSON API installation, you can construct an instance of a WordPressClient with your own Transformer/POJO pair that's suitable for your organization.

Including this JAR

Add this dependency to your Maven POM:

endency>
<groupId>com.washingtonpost.wordpress</groupId>
<artifactId>wordpress-rest-api-client</artifactId>
<version>x.y.z</version>  // Check RELEASE_NOTES.md for the best version for your needs
pendency>
Constructing a default client with BasicAuth autentication:
rt com.washingtonpost.wordpress.rest.api.JAXRSWordPressClient;
rt com.washingtonpost.wordpress.rest.api.JAXRSWordPressFactory;

ic class FooClazz {

public void myMethod() {
    JAXRSWordPressClient myClient = (new JAXRSWordPressFactory())
                                           .withBaseUrl("http://wordpress.foo.com/wp-json")
                                           .withCredentials("joe", "secret")
                                           .build();
    ...
}
Testing with this client

This client ships with a MockWordPressClient that loads a classpath resource and returns the JSON contents of that resource as fixture data, like so:

rt com.washingtonpost.wordpress.rest.api.model.WordPressPost;

ic class TestJAXRSWordPressClient {

@Test
public void testHappyPath() throws IOException {
    WordPressClient client = new WordPressClientFactory()
                                    .withMockResource("off-the-shelf-response.json")
                                    .build();
    ...
}
Extending Functionality

To use this client to parse a different batch of JSON than comes with the standard WordPress REST API, implement 2 classes:

Register your transformer with the Client when you use the ClientFactory to create your Client instance, like:

SWordPressClient myClient = (new JAXRSWordPressFactory())
                                           .withTransformer(new MySpecialTransformer())
                                           .withBaseUrl("http://wordpress.foo.com/wp-json")
                                           .build();

What this Client doesn't (yet) support


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.