SlideShare a Scribd company logo
WP REST APIAn introduction and demonstration
17 June 2019
Edmund Chan
edmund@nerb.com.sg //
https://github.com/edmundcwm
Developer
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
What is an API?
Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
What is an API?
Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
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
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)
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
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
How does it look like
https://yoursite.com/ wp-json/wp/v2/posts
How does it look like
https://yoursite.com/ wp-json/wp/v2/users/1
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
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/
Use-cases
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
Use-cases
Demonstration
Edmund Chan
edmund@nerb.com.sg //
https://github.com/edmundcwm
Developer

More Related Content

Similar to An Introduction to the WP REST API

Weekly Tech Session
Weekly Tech SessionWeekly Tech Session
Weekly Tech Session
Pravin Vaja
 
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Evan Mullins
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIs
anandology
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
Gabriel Lucaciu
 
Role of Rest vs. Web Services and EI
Role of Rest vs. Web Services and EIRole of Rest vs. Web Services and EI
Role of Rest vs. Web Services and EI
WSO2
 
Hypermedia
HypermediaHypermedia
Hypermedia
Adam Culp
 
Drupal As A RESTful Backend For Client Side Applications
Drupal As A RESTful Backend For Client Side ApplicationsDrupal As A RESTful Backend For Client Side Applications
Drupal As A RESTful Backend For Client Side Applications
Myplanet Digital
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
Eugen Paraschiv
 
PHP on Windows
PHP on WindowsPHP on Windows
PHP on Windows
Maarten Balliauw
 
PHP on Windows
PHP on WindowsPHP on Windows
PHP on Windows
guest60c7659
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
Smile I.T is open
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
MongoDB
 
Web APIs
Web APIsWeb APIs
Web APIs
Carlos Santos
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communication
Pivorak MeetUp
 
Word press rest api sudarshan shrestha
Word press rest api  sudarshan shresthaWord press rest api  sudarshan shrestha
Word press rest api sudarshan shrestha
Sudarshan Shrestha
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
Tatiana Al-Chueyr
 
RESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel MardjanRESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel Mardjan
Jexia
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 

Similar to An Introduction to the WP REST API (20)

Weekly Tech Session
Weekly Tech SessionWeekly Tech Session
Weekly Tech Session
 
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIs
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
 
Role of Rest vs. Web Services and EI
Role of Rest vs. Web Services and EIRole of Rest vs. Web Services and EI
Role of Rest vs. Web Services and EI
 
Hypermedia
HypermediaHypermedia
Hypermedia
 
Drupal As A RESTful Backend For Client Side Applications
Drupal As A RESTful Backend For Client Side ApplicationsDrupal As A RESTful Backend For Client Side Applications
Drupal As A RESTful Backend For Client Side Applications
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
 
PHP on Windows
PHP on WindowsPHP on Windows
PHP on Windows
 
PHP on Windows
PHP on WindowsPHP on Windows
PHP on Windows
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Web APIs
Web APIsWeb APIs
Web APIs
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communication
 
Word press rest api sudarshan shrestha
Word press rest api  sudarshan shresthaWord press rest api  sudarshan shrestha
Word press rest api sudarshan shrestha
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
RESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel MardjanRESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel Mardjan
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 

Recently uploaded

Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 

Recently uploaded (20)

Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 

An Introduction to the WP REST API

  • 1. WP REST APIAn introduction and demonstration 17 June 2019
  • 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. What is an API? Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
  • 5. What is an API? Credit: https://medium.com/@tyteen4a03/how-apis-work-an-analogy-for-dummies-ac6ee1d1671b
  • 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. 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. 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. 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. How does it look like https://yoursite.com/ wp-json/wp/v2/posts
  • 11. How does it look like https://yoursite.com/ wp-json/wp/v2/users/1
  • 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. 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/
  • 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

Editor's Notes

  1. Using a Bank as an analogy Imagine a bank without any tellers or staff working there. Its vault and logbook are publicly accessible. So to deposit money, the customer just needs to walk in, open the vault, deposit money and record how much he/she puts into the bank. Problem #1 Vault too heavy. Customer unable to open it. Or logbook is complicated. Customer doesn’t know how to read or write Problem #2 Customer is dishonest. Deposits $500 but records $1000 in logbook
  2. Using a Bank as an analogy Solution – hire a bank teller Customer will pass money to bank teller. Teller takes the money, opens the vault and puts in the money. Teller will also record this transaction. Teller then informs customers that money has been deposited. Customer leaves the bank with a smile With a bank teller, we have introduced the concept of an API. As mentioned at the start, API allows you to talk to other application easily. So now the customer doesn’t need to open the heavy vault door and write into the complicated logbook anymore.
  3. A REST or RESTful API is a type of API that uses HTTP requests to perform CRUD operations HTTP is the foundation of how we share data online. Essentially it comprises of two aspects – Request and Response e.g., type a url in the browser toolbar (request) and the server provides a response Protocol is the set of rules defining how components can interact with one another With regard to analogy Bank teller understands the request of withdrawing and depositing money. But doesn’t understand if the customer ask to help book movie tickets. So both parties must understand the same protocol in order for the communication to be successful Format is how the components talk to each other With regard to analogy Both customer and teller are speaking in English and it is something both understand. So the communication is a success. But if customer speaks in Chinese, the teller wouldn’t understand. With the REST API, it securely exposes your data to HTTP requests from external sources. A website or application on another server can use the REST API to retrieve information from your WP site
  4. In the context of WP POST = use your app and create a new blog post GET = display 10 latest posts in your app or retrieve users information PUT = update blog post content DELETE = remove blog post This is also commonly known as the CRUD operations Later on in the demo, we will take a look at a simple app that can perform these operations
  5. WP now has its very own fully-functional REST API Full introduced in 4.7 The infrastructure was first merged into core in v4.4. The remaining parts of the API was introduced in 4.7. So if your site is running 4.7 or later, you will have access to the WP REST API Own set of rules and methods For sending and receiving data to manipulate WordPress Content Modernising WP - Web applications are becoming more popular and common and this has led to the rise in popularity of JavaScript. In that regard, WP can feel a bit outdated as it is primarily PHP-based and there is minimal use of JavaScript. With the introduction of the WP REST API, JavaScript developers will now be able to build apps using WP as the backend.
  6. Also commonly known as the CRUD operations, the REST API allows us to create, read, update and delete data form anywhere. This opens the door for all kinds of possibilities. We can create a mobile app that uses WP as the backend and then use the REST API to create, read, update and delete content. We don’t have to login to the admin dashboard to do all these anymore. Use WP as a storage and retrieval system -By using the WP REST API, developers can utilise WP’s infrastructure for storing and retrieving data and focus on developing apps powered by other languages like Python, Ruby and Java.
  7. If your WP site is running at least version 4.7 (which it should be, mainly for security reasons), you can visit your site and append the following route to retrieve various information. In this case, this will display our all posts from your site. By default the output will not be formatted nicely like this. It’s actually just one messy wall of text with no proper line breaks and indentations. I’m using a Chrome extension called ‘JSON View’ which helps to make it more readable. So this endpoint here uses the ‘GET’ method to retrieve all public posts from your site. There are actually a lot more information available like the author id, categories etc. but I had to crop it to make it fit. Some of the more common and useful pieces of info that will be used are the ID, title and content.
  8. This is the USERS endpoint. As you can see, it displays only the necessary information and hides those private data like your password. The /1 at the end is the user ID. So this endpoint will only display the information of user id 1. An example of when this endpoint can be useful is when developing a simple search function. You can have an input field in your app for users to enter and ID. U can then take the value the user entered and append to the end of the route. So if users enter ‘2’, it will be /users/2 and so on. And the REST API will retrieve information of author with the ID 2.
  9. The blue part Namespace is used as prefixes to prevent clashes with custom routes. For e.g., when creating a custom route without namespace, it might look something like /wp-json/books. Since /books is a fairly common term, the chances of other developers using the same route are quite high. And when they do, conflicts will happen. ‘v2’ is the version part of the namespace. This is useful for maintaining backwards compatibility. If u are writing your own REST endpoint and want to add new ones, u can just bump the version up to v3 or something so the old versions will still be accessible. Resource path This is the resource we want to retrieve from the server. As shown in the previous slide, /posts retrieve all posts, /users retrieve all users. There is also /pages which retrieves info on all the pages. Route This is the name you use to access a required endpoint Endpoints Endpoints are functions that allow u to perform CRUD operations. And we use routes to access endpoints. For example, if I want to retrieve the all the posts from this site, I’d go to the /wp/v2/posts route and it will trigger the ‘GET’ endpoint A route can have multiple endpoints. This /wp/v2/posts route has 2 endpoints and which is used depends on the HTTP method (POST, GET) So if I use the POST method, I will be able to insert a new post.
  10. Headless CMS no front-end display only uses WP to store and manage content uses the WP REST API to retrieve and manipulate data App can be on a separate server