{"id":139676,"date":"2020-03-03T11:00:00","date_gmt":"2020-03-03T17:00:00","guid":{"rendered":"https:\/\/getflywheel.com\/?p=15746"},"modified":"2024-09-10T12:18:43","modified_gmt":"2024-09-10T17:18:43","slug":"wordpress-api-basics-what-is-means-and-how-to-use-it","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/","title":{"rendered":"WordPress APIs: What Are They and How to Use Them"},"content":{"rendered":"\n<p>The WordPress <a href=\"https:\/\/developer.wordpress.org\/rest-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">JSON REST API<\/a> has created quite a buzz in the WordPress community, offering new possibilities for developers and content creators alike.<\/p>\n\n\n\n<p>While it may sound complex, understanding key terms like <a href=\"https:\/\/www.json.org\/json-en.html\" target=\"_blank\" rel=\"noreferrer noopener\">JSON<\/a>, <a href=\"https:\/\/www.codecademy.com\/article\/what-is-rest\">REST<\/a>, and <a href=\"https:\/\/en.wikipedia.org\/wiki\/API\">API<\/a> can simplify how you interact with WordPress\u2019 wide-ranging capabilities. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is an API? <\/h2>\n\n\n\n<p>API stands for \u201capplication programming interface,\u201d which is essentially a set of programming instructions and standards that allow different software applications to communicate with each other. <br><br>Imagine one software application giving directions to another\u2014an API is the set of agreed-upon rules that govern this interaction. When one piece of software sends instructions to another, the API facilitates the action or provides the necessary information. <\/p>\n\n\n\n<p>You can think of an API as the &#8220;user interface&#8221; between two software systems, handling the communication of data and task execution, but invisible to the end user.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/03\/wordpress-api-software-to-software.png\" alt=\"a laptop on a wooden desk\" class=\"wp-image-15860\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Examples of APIs<\/h3>\n\n\n\n<p>Having access to an API is awesome when you\u2019re developing web applications. When an API is released to the public, it means the developers created solutions that are powered by the software\u2019s service. Oftentimes, they take away the need to reinvent the wheel for many tasks, since they have already been created.<\/p>\n\n\n\n<p>A great example of an API is Amazon. <a href=\"https:\/\/docs.aws.amazon.com\/apigateway\/latest\/developerguide\/welcome.html\" target=\"_blank\" rel=\"noreferrer noopener\">Amazon released its API<\/a> so that developers can easily access products and their information. Having access to this makes it easy to post links to products on Amazon, with updated prices and the option to buy.<\/p>\n\n\n\n<p>Another example of APIs interacting would be concert ticket purchases. To officially purchase tickets, you need to enter your credit card information. An API is used to send your credit card information to a remote application, which then verifies that the credit card information is correct. <\/p>\n\n\n\n<p>Once everything checks out, the remote application sends a response back to the ticket website saying it\u2019s okay to proceed, at which point you\u2019ve successfully purchased the tickets. When all this is going on, you only see one interface, which is the ticket website. It\u2019s a seamless process; behind the scenes, many applications are working together using APIs, but you as the user don\u2019t notice when tasks are handed from one application to another.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">APIs and WordPress<\/h3>\n\n\n\n<p>Amazon and ticket purchases are great examples of how APIs work together, but how does this apply to WordPress?<\/p>\n\n\n\n<p>Well, all the same ideas apply. With the WordPress API, you are able to push and pull data into and out of WordPress.<\/p>\n\n\n\n<p>The API is a key tool that developers can use to easily share data from their WordPress website to other websites or applications. Specifically, this API lets you perform <code>create<\/code>, <code>read<\/code>, <code>update<\/code>, and <code>delete<\/code> (CRUD) actions on WordPress content. A few examples of the content types are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Posts<\/li>\n\n\n\n<li>Custom post types<\/li>\n\n\n\n<li>Pages<\/li>\n\n\n\n<li>Taxonomies<\/li>\n\n\n\n<li>Users<\/li>\n\n\n\n<li>Media<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What does REST mean?<\/h2>\n\n\n\n<p>There\u2019s no napping or snoring here\u2014REST refers to the architectural style of an API. REST stands for Representational State Transfer. <\/p>\n\n\n\n<p>Remember how we mentioned that an API gives the specifics for communication so programs can communicate with each other? REST API\u2019s are designed in such a way that they provide a lightweight method of communication, which saves bandwidth. The WordPress JSON REST API does just this, making it a great option when there is a high volume of data.<\/p>\n\n\n\n<p>We\u2019ve just scratched the surface of REST; if you\u2019d like to learn more, check out this <a href=\"http:\/\/www.restapitutorial.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">REST helpful tutorial<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSON format<\/h3>\n\n\n\n<p>To access data, we need a source to pull from. This is where JSON comes in. JSON stands for JavaScript Object Notation. <\/p>\n\n\n\n<p>JSON is easy for both humans and machines to read and understand. It\u2019s the perfect way to store information in an organized, easy-to-access manner. Because JSON is so simple to access, this makes it a great fit for creating REST APIs and is the perfect solution for the WordPress JSON REST API.<\/p>\n\n\n\n<p>Here\u2019s a basic idea of what JSON format looks like:<\/p>\n\n\n<p>[javascript]<br \/>\n{&#8220;employees&#8221;:[<br \/>\n{&#8220;firstName&#8221;:&#8221;Jane&#8221;, &#8220;lastName&#8221;:&#8221;Smith&#8221;},<br \/>\n{&#8220;firstName&#8221;:&#8221;Anna&#8221;, &#8220;lastName&#8221;:&#8221;Olsen&#8221;},<br \/>\n{&#8220;firstName&#8221;:&#8221;Josh&#8221;, &#8220;lastName&#8221;:&#8221;Jones&#8221;}<br \/>\n]}<\/p>\n<p>[\/javascript]<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSON format in WordPress<\/h3>\n\n\n\n<p>JSON doesn\u2019t just write itself, but don\u2019t worry, you don\u2019t have to manually create the JSON file. There are plugins that can create it for you. With one of these tools, the site\u2019s data will be in the correct format, including users, posts, pages, taxonomies, and more. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using the JSON REST API<\/h3>\n\n\n\n<p>Using the API is pretty self-explanatory; you\u2019ll be grabbing your site&#8217;s data in simple JSON format. And if you have a plugin installed, you can play around with seeing your site&#8217;s posts in data form.<\/p>\n\n\n\n<p>Retrieving or updating data is as simple as sending an HTTP request. HTTP is a request\/response protocol. First, you send a request for data and then the data is is sent back as a response.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">GET method<\/h3>\n\n\n\n<p>The GET method is used to retrieve information and has no effect on the data. Simply send a GET request to <code>\/wp-json\/wp\/v2\/posts<\/code>. Want to search for something? For example, if you\u2019re searching &#8220;development&#8221; you\u2019ll get the results with the GET request <code>\/wp-json\/wp\/v2\/posts?search=development<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">POST request<\/h3>\n\n\n\n<p>A POST request is used to send data. With the capabilities of the new API, for example, you could update a user. Let\u2019s say you want to update the user with the ID of 10. All you have to do is send a POST request to <code>\/wp-json\/wp\/v2\/users\/10<\/code>.<\/p>\n\n\n\n<p>To try this out, we\u2019d recommend using <a rel=\"noopener noreferrer\" href=\"https:\/\/chrome.google.com\/webstore\/detail\/postman\/fhbjgbiflinjbdggehcddcbncdddomop?hl=en\" target=\"_blank\">Postman<\/a>, a Google Chrome extension.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">More Javascript in the mix<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Backbone.js and APIs<\/h3>\n\n\n\n<p><a rel=\"noopener noreferrer\" href=\"http:\/\/backbonejs.org\/\" target=\"_blank\">Backbone.js<\/a> is a great way to work with the API because it is a framework designed for working with REST APIs. The WordPress API includes an easy-to-use Javascript API based on Backbone models. This allows plugin and theme developers to get up and running without super in-depth effort and knowledge about the details of getting connected. <\/p>\n\n\n\n<p>There\u2019s a lot more to it, but Backbone gives structure to web applications by providing models, collections, and views, and connects it all to the WordPress API over a REST JSON interface.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2016\/03\/wordpress-api-backbone.png\" alt=\"backbone.js wordmark logo\" class=\"wp-image-15855\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What does this mean for WordPress developers?<\/h2>\n\n\n\n<p>With the availability of the WordPress API, new ways of utilizing it have increased and will continue to do so as it gains popularity. The WordPress API can improve just about any existing WordPress functionality that relies on Javascript. Here are a few examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>form validation\/submission<\/li>\n\n\n\n<li>Backbone.js themes or plugins<\/li>\n\n\n\n<li>infinite scrolling<\/li>\n<\/ul>\n\n\n\n<p>It\u2019s also a great way to show content from other sources. Now, it is easy to display content from an individual site within a multisite setup. It\u2019s also possible to display content from an entirely separate WordPress site. In addition to showing content, the content can also be updated more easily and effectively.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Now that we\u2019ve gone over some of the basic terminology, we know that JSON is the notation, REST is the architectural style, and API is the interface they make up. Knowing the basics of the API and its capabilities will ensure you are off to a good start when you explore the new possibilities with the WordPress API.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The WordPress JSON REST API has created quite a buzz in the WordPress community, offering new possibilities for developers and content creators alike. While it may sound complex, understanding key terms like JSON, REST, and API can simplify how you interact with WordPress\u2019 wide-ranging capabilities. What is an API? API stands for \u201capplication programming interface,\u201d<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":1,"featured_media":153381,"template":"","resource-topic":[912,898],"resource-role":[1397,896,899],"resource-type":[916],"class_list":["post-139676","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WordPress APIs: What Are They and How to Use Them<\/title>\n<meta name=\"description\" content=\"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress APIs: What Are They and How to Use Them\" \/>\n<meta property=\"og:description\" content=\"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-10T17:18:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2024\/03\/API-101_1200x627.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"627\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2024\/03\/API-101_1200x627.png\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/\",\"name\":\"WordPress APIs: What Are They and How to Use Them\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2020-03-03T17:00:00+00:00\",\"dateModified\":\"2024-09-10T17:18:43+00:00\",\"description\":\"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"WordPress APIs: What Are They and How to Use Them\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085\",\"name\":\"WP Engine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"caption\":\"WP Engine\"},\"sameAs\":[\"https:\/\/wpengine.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress APIs: What Are They and How to Use Them","description":"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"WordPress APIs: What Are They and How to Use Them","og_description":"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2024-09-10T17:18:43+00:00","og_image":[{"width":1200,"height":627,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2024\/03\/API-101_1200x627.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2024\/03\/API-101_1200x627.png","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/","name":"WordPress APIs: What Are They and How to Use Them","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2020-03-03T17:00:00+00:00","dateModified":"2024-09-10T17:18:43+00:00","description":"Understand the basics of the WordPress APIs, including what they are, how they work, and how you can use APIs to enhance site functionality.","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-api-basics-what-is-means-and-how-to-use-it\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"WordPress APIs: What Are They and How to Use Them"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085","name":"WP Engine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","caption":"WP Engine"},"sameAs":["https:\/\/wpengine.com"]}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2024\/03\/API-101_343x245.png","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Designer, Developer, Site Owner","topic":"<strong>Topics:<\/strong> Performance, Scalability","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/139676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/153381"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=139676"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=139676"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=139676"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=139676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}