Created
October 3, 2019 18:02
-
-
Save rieckpil/e019cf7c05afbbcad964efa897008f0b to your computer and use it in GitHub Desktop.
WP API get all posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class WpClient { | |
public void getListOfBlogPosts(@Observes @Initialized(ApplicationScoped.class) Object object) { | |
Client client = ClientBuilder.newBuilder().build(); | |
WebTarget webTarget = client.target("https://rieckpil.de/wp-json/wp/v2/posts"); | |
JsonArray result = webTarget | |
.queryParam("per_page", 100) | |
.request() | |
.accept(MediaType.APPLICATION_JSON) | |
.get(JsonArray.class); | |
List<String> allBlogPosts = result | |
.stream() | |
.filter(jsonValue -> jsonValue.asJsonObject().getString("link").contains("how")) | |
.map(jsonValue -> jsonValue.asJsonObject().getJsonObject("title").getString("rendered")) | |
.collect(Collectors.toList()); | |
for (String title : | |
allBlogPosts) { | |
System.out.println(title); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment