5. Access WP Data from anywhere
Use WP for data, and build custom apps
Build/Extend APIs
Much, much more
westwerk.com
WP RESRT API V2
WHAT CAN WE DO WITH IT?
6. What am I excited about?
Performance
Client Side Apps
Better Migration Options
9. Performance
FULL HTTP LOAD
TWENTYFIFTEEN THEME
HELLO WORLD POST
JSON LOAD
HELLO WORLD POST
LOADING POST COMPARISON
262KB
578 MS LOAD
1.2 SEC FINISH
19 REQUESTS
2.1KB
236 MS LOAD
250 MS FINISH
1 REQUESTS
16. Lightweight Data Exchange format
Easy for Humans to read
Easy for Machines to parse/generate
Very similar to JavaScript Objects
westwerk.com
JSON
JAVASCRIPT OBJECT NOTATION
17. Squiggly brackets act as objects (containers)
Square brackets holds arrays
Names and values are separated by a colon
Array elements are separated by commas
westwerk.com
JSON
STRUCTURE
29. Lean how to “query” the API
http://v2.wp-api.org/
30. WP_Query
$query = new WP_Query(array(
‘post_per_page’=> 1,
‘orderby’ => ‘rand’,
));
/wp-json/wp/v2/posts/?
filter[posts_per_page]=2&filter[orderby]=rand
REST API
31. Now in JavaScript
(jQuery for simplicity)
$.ajax({
dataType: 'json',
type: 'GET',
url: 'http://wpapi.dev/wp-json/posts',
data: {
filter: {
'posts_per_page': 5,
'orderby': 'rand'
}
},
success: function(data) {
// Do something with the data
}
});
33. Checklist
1. Learn About REST/JSON
2. Setup/Install
3. Access
4. Using JS
5. Practical Example. More?
Go and explore on your own:
http://v2.wp-api.org/