Creating a custom API

Custom APIs are essential for adding web application specific behaviors, which goes beyond the generic blogging functionality. We need the implementation for both the server and client to create a custom API. Here, we are going to build an API function that outputs the list of developers in a portfolio application. As usual, we are going to get started by creating another plugin folder named wpwa-xml-rpc-api with the main file named class-wpwa-xml-rpc-api.php.

Let's look at the initial code to build the API server:

class WPWA_XML_RPC_API { public function __construct() { add_filter('xmlrpc_methods', array($this, 'xml_rpc_api')); } public function xml_rpc_api($methods) { $methods['wpwa.getDevelopers'] = array($this, 'developers_list'); ...

Get WordPress Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.