Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WP REST API and YOU -> BEST FRIENDS FOREVER - Craig West

WP REST API and YOU -> BEST FRIENDS FOREVER - Craig West

Using the WP REST API for pages and forms
This workshop is aimed to demystify the WordPress REST API and enable you to create pages and forms that do not need to be refreshed.
Furthermore, by being comfortable with the WP REST API, you will be able to import and export data not just with other WP sites but also any site or framework.
Extraordinarily little JavaScript is needed in this workshop and the concepts of Fetch requests and JSON data will be explained.
With code files, easy WP site clone, manual and follow-up videos, we will build a site with AJAX pages and forms including the use of WP Nonce for security.
Finally, we will take a quick look at how by using the combination of Custom HTML tags and WP REST API, we can create HTML plugins for any site or framework that uses just two lines of HTML!

WordPress Greek Community

April 16, 2021
Tweet

More Decks by WordPress Greek Community

Other Decks in Technology

Transcript

  1. WordPress Greece Online WordPress REST API Craig West If you

    want to follow along with code, please have a new install of WP ready. I will go through cloning the site we will be using. April 2001
  2. Agenda • Understand WP REST API, AJAX, JSON. • How

    to use the FETCH API to get/post data. • Know how to create custom WP REST API Endpoints • Use them for GET/POST requests • Create forms that use these endpoints • Secure forms with WP NONCE. • Using endpoints from other sites.
  3. 1980: At University, I studied Chemistry and used MS-DOS, client/server

    main frame systems, ZX-Spectrum computer and Jupiter Ace recreationally. Former careers as accountant, SQL Server DBA and Business Information Architect. And a (proud) plumber! Source:Wikimedia Commons Source:Wikimedia Commons Source:Wikimedia Commons Source:Wikimedia Commons Brighton, UK Trainer PWAs, Web Components & RxJS http://www.map-of-uk.co.uk/ 80 km
  4. WordPress REST API • What is REST? • This was

    formulated by Roy Fielding for his thesis in 2000. • An architectural style not a protocol. • HTTP by its nature is implicitly RESTful. • https://www.ics.uci.edu/~fielding/pubs/dissertation/ rest_arch_style.htm
  5. Endpoints HTTP VERB + URL = ENDPOINT GET/POST + same

    URL = 2 ENDPOINTS https://wpjs.co.uk/wpb/wp-json/wp/v2/posts GET/POST/DELTE
  6. Ajax AJAX = Asynchronous JavaScript And XML. Read data from

    a web server without reloading the page Update a web page Send data to a web server - in the background
  7. JSON – JavaScript Object Notation JSON is a lightweight format

    for storing and transporting data JSON is often used when data is sent from a server to a web page JSON is "self-describing" and easy to understand. Data is in name/value pairs separated by commas. Essentially arrays of arrays.
  8. Strings – Booleans – Numbers Null – Object - Array

    https://wpjs.co.uk/wpb/wp-json/wp/v2/posts JSON – Data Types
  9. Workshop resources The following link has the workshop manual, code

    and also the ability to clone the WP site. We will go through how to clone the site.
  10. Wrap Up There is free online course covering what we

    have done today. The link is valid for 3 days. If you have any questions please feel free to contact me: [email protected]