Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WP REST API - Building a simple Web Application

Presentation slides for WordCamp Singapore 2019 Contributor's day. Visit to view other presentation resources.

  • Be the first to comment

  • Be the first to like this

WP REST API - Building a simple Web Application

  1. 1. WP REST API Building a Simple Web Application WordCamp Singapore 2019
  2. 2. slack/
  3. 3. Edmund Chan Developer
  4. 4. WP REST API introduction-to-the-wp-rest-api
  5. 5. WP REST API • Representational State Transfer (RESTful) API – Uses HTTP protocol (almost always) and its delivery methods – Uses JavaScript Object Notation (JSON) format to exchange data
  6. 6. WP REST API • Four main request methods (CRUD) – GET (retrieve data to server) – POST (send data to server) – PUT (change or update data on server) – DELETE (remove data from server)
  7. 7. WP REST API • Why is it useful? – Universal Connector from WP to external apps (JS, Ruby, Python, iOS/Android etc – Allows us to Create, Read, Update and Delete data from anywhere – We are not restricted to the admin dashboard screen
  8. 8. Building the App What we will be building today…
  9. 9. Building the App
  10. 10. Building the App • Purpose – provide a quick and simple way to publish short messages. – suitable for note-taking/micro-blogging. – demonstrate the CRUD operation. • Approach – Use WordPress as the backend for storing and retrieving data – Frontend will be built using jQuery Note: this tutorial assumes you have basic knowledge of JavaScript and jQuery. We will be utilising things like arrays, functions and AJAX.
  11. 11. Building the App Server MAMP running on PHP 7.1 and MySQL 5.7.23 WordPress 5.2.2 (has to be at least 4.7) Plugins Basic Auth ( Browser Chrome v76
  12. 12. Building the App Getting started: 1. Setup WordPress 2. Install Basic Auth plugin - 3. Download app files - api 4. Visit - - to ensure everything is fine
  13. 13. Building the App wp-json/wp/v2/posts
  14. 14. Building the App TO-DOs: 1. Insert AJAX call to RETRIEVE all posts via the WP REST API 2. Insert AJAX call to CREATE post via the WP REST API 3. Insert AJAX call to DELETE post via the WP REST API 4. Insert AJAX call to UPDATE post via the WP REST API
  15. 15. Building the App Retrieve Posts Method: GET Endpoint: /wp/v2/posts
  16. 16. Building the App Create Post Method: POST Endpoint: /wp/v2/posts
  17. 17. Building the App Delete Post Method: DELETE Endpoint: /wp/v2/posts/(id)
  18. 18. Building the App Update Post Method: PUT Endpoint: /wp/v2/posts/(id)
  19. 19. slack/
  20. 20. Edmund Chan Developer