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.

An Introduction to the WP REST API

57 views

Published on

Presentation slides for the 17th June 2019 WordPress Singapore Meet-up. Visit https://www.edmundcwm.com/presentations/ to view other presentation resources.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

An Introduction to the WP REST API

  1. 1. WP REST APIAn introduction and demonstration 17 June 2019
  2. 2. Edmund Chan edmund@nerb.com.sg // https://github.com/edmundcwm Developer
  3. 3. What is an API? • Application Programming Interface – Rules and instructions for applications to communicate – Secure method for third-party apps to use your program and data – E.g., Twitter, Instagram, Google Maps, POS system
  4. 4. What is an API? Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
  5. 5. What is an API? Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
  6. 6. What is an API? • Representational State Transfer (RESTful) API – Uses HTTP protocol (almost always) and its delivery methods – Uses JavaScript Object Notation (JSON) format to exchange data
  7. 7. HTTP Methods • Four main methods (CRUD) – GET (retrieve data to server) – POST (send data to server) – PUT (change or update data on server) – DELETE (remove data from server)
  8. 8. What is the WP REST API? • A fully-functional REST API in WP – Fully introduced in 4.7 – Its own set of rules and methods – Means of ‘modernising’ WP
  9. 9. Why is the WP REST API useful? • Universal connector from WP to external applications – Allows us to Create, Read, Update and Delete data from anywhere – External applications (JS, Ruby, Python etc.) – Native mobile apps (iOS/Android etc.) – We are not restricted to the admin dashboard screen
  10. 10. How does it look like https://yoursite.com/ wp-json/wp/v2/posts
  11. 11. How does it look like https://yoursite.com/ wp-json/wp/v2/users/1
  12. 12. How does it look like • https://yoursite.com/wp-json/wp/v2/posts – /wp-json – base path of the API – /wp/v2 – namespace – /posts – resource path – /wp/v2/posts - Route/Endpoint
  13. 13. Use-cases • Calypso – Single Page App (SPA) to manage all WordPress.com or Jetpack- enabled sites – Built entirely in JavaScript – Communicates with WordPress.com only using the WP REST API – https://developer.wordpress.com/calypso/
  14. 14. Use-cases
  15. 15. Use-cases • Digital Scoring App – Developed for a race event – Two main modules - participants and game masters – Uses JWT (JSON Web Tokens) Authentication – Uses WP as a Headless CMS
  16. 16. Use-cases
  17. 17. Demonstration
  18. 18. Edmund Chan edmund@nerb.com.sg // https://github.com/edmundcwm Developer

×