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

7 views

Published on

Presentation slides for WordCamp Singapore 2019 Contributor's day. Visit https://www.edmundcwm.com/presentations/ to view other presentation resources.

Published in: Internet
  • 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. https://wpug.sg/join-us-on- slack/
  3. 3. Edmund Chan edmund@nerb.com.sg Developer
  4. 4. WP REST API https://www.slideshare.net/EdmundChan31/an- 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 https://www.mamp.info/en/mamp/ https://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP WordPress 5.2.2 (has to be at least 4.7) Plugins Basic Auth (https://github.com/WP-API/Basic-Auth) Browser Chrome v76
  12. 12. Building the App Getting started: 1. Setup WordPress 2. Install Basic Auth plugin - https://github.com/WP-API/Basic-Auth 3. Download app files - https://github.com/edmundcwm/micro-blog-wp-rest- api 4. Visit - https://yoursite.com/wp-json/wp/v2/posts - to ensure everything is fine
  13. 13. Building the App https://yoursite.com/ 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. https://wpug.sg/join-us-on- slack/
  20. 20. Edmund Chan edmund@nerb.com.sg Developer

×