Join Morten Rand-Hendriksen for an in-depth discussion in this video What are RESTful APIs and JSON?, part of WordPress: REST API.
- [Instructor] When we work with RESTful APIs, there is a lot of new acronyms, terms, and terminology, so let's get acquainted with these before we dive any deeper. You'll hear me use these terms throughout the course and you'll also discover they are not specific to WordPress so learning and understanding them will be a big help as you move from basic PHP-based applications to the wonderful world of RESTful APIs. Actually, let's start there with REST and API. REST is an acronym that stands for Representational State Transfer and it describes the software architecture of the web.
A RESTful application is typically one that uses standard verbs like get, post, put, delete, and so on to retrieve and send data to and from a remote server. RESTful applications use URIs pointing at resources, those are objects that contain data, to interface with external systems such as a remote server, and uses verbs to perform operations on those resources on the server either retrieving data, creating new data, or changing the data in some way. API is an acronym for Application Programming Interface, a set of routines, protocols, and tools for building applications and interfaces.
JSON is an open standard format that is used to transmit data objects in the form of attribute-value pairs for further processing. JSON is commonly used for asynchronous communication between browsers and servers, the kind of communication performed by RESTful APIs and is favored over XML because it's cleaner and easier to work with. So if we put all of this together, the WordPress REST API is a RESTful API for WordPress that returns data objects in the JSON format when provided with URIs pointing at a resource.
- Using a REST client to communicate with a REST API
- Reviewing available routes, endpoints, and arguments
- Adding custom post types and taxonomies
- Altering the API response
- Using PHP for resiliency
- Passing info using wp_localize_script()
- Setting up a REST API request through AJAX
- Outputting selected post data to the front end
- Formatting post data to match a theme
- Triggering AJAX for an infinite scroll effect
- Using AJAX to load subsequent responses