 Thank you. You can call me Crystorella. It's okay. I will respond to that So, I don't know if you remember the default WordPress tagline just another WordPress site. So this kind of is just another rest API talk But I thought that sounded lame so it's not just another rest API talk I Am Kristen Simons At Crystorella on Twitter The real Crystorella on Instagram because I held out and then I lost my name I am a happiness engineer working for automatic mainly supporting WordPress.com Yes, thank you. There are a few automaticians here this weekend. It's great. I Am one of two automaticians currently living in Sydney Sadly, you can't see the other ones avatar. It's like stuck behind me there and So just an overview of where we're going today So I'm going to talk a bit about what a rest API is so WordPress isn't the only thing that has a rest API it's a More specific thing and then what is the WordPress rest API a bit of history about it who is currently using it? How you can use it? Some ideas and a couple of examples So what is a rest API? It's not about resting or napping or anything like that And API is an application programming interface So it's a way for different applications different websites to talk to each other and It the phrase rest was coined by Roy Roy Fielding in his dissertation in 2000 It stands for representational state transfer so basically, you've got a text representation of something information and You can transfer that You can get the information You can manipulate manipulate the information through the API So what makes a API restful as opposed to not restful six specific things One is that it needs to be stateless So that kind of means that it doesn't matter if it's your first request or your fifth request That API doesn't care it also doesn't rely on previous information So an example of a not stateless task is like a form or a survey where you You know, you have to go through each page in turn The statelessness of the rest API means that you don't do that You send all the information in one go and you get information back It should be cacheable That's kind of self-explanatory You guys don't need to worry about that Ryan needs to worry about that when he's making the API It should have a uniform interface So that means that a URI or a URL Identifies the thing the resource that you want to get or perform an action on and Generally the operation that you want to perform should be implicit in the URL, but as you'll see later It might not be so in this example You've got your website and then delete is the method or the operation product is the Sort of the type product coffee is the type of resource But sometimes your method will go in another part of your code So The rest a rest API should have a separation of client and server so The server doesn't really care who the client is And the client doesn't need to store information that's kind of similar to the statelessness in that It doesn't matter if the client has made ten or twenty requests It should be layered so or it should be able to be layered so it doesn't matter if You're accessing the original source of the information. You could be accessing through an intermediary server so It could be a CDN or something like your information could be stored multiple levels down on multiple locations and API doesn't care about that and The response This one's kind of optional But be in a hypermedia format so hypermedia meaning that it should have a Sort of a semantic sense of what the information is within it So XML is a hypermedia format because it conveys the meaning of the information within it Jason is the format that there were a lot of rest API's return and It is sometimes hypermedia. So it's up to the author of the API to make The Jason that's returned Makes sense so instead of saying here's my resource and then just saying and value one is blah and value two is Something else you would say here's my resource and its ID is and its link is So you wouldn't assign, you know actual value one because that doesn't convey any meaning So that's what makes an API restful What is the WordPress rest API? So WordPress has lots of API's or like not heaps, but it has multiple So it has the theme API and the plug-in API But none of those are restful. They're all dependent on You interacting with them via PHP So I Like the way that Topha de Rossia said it The rest the WordPress rest API immediately turns your website into an application That can serve data to any kind of application or language so the WordPress rest API breaks down barriers between languages and servers to Provide information from one WordPress installation to another or to Change your WordPress the information stored in your WordPress install from another location It's a bit of a timeline of how the WordPress rest API came about so in back in 2009 this isn't exactly or Necessarily part of the current rest API's process, but it's just interesting that in 2009 the Museum of Modern Art in New York They wanted to use WordPress To manage their website content, but they wanted to build a front-end in Ruby Each to their own So they made a Jason API plug-in for Developing their website So that's not I don't believe that's what actually evolved into the current rest API, but back then Somebody was thinking that hey, it'd be good if WordPress had an API that output information in Jason So then in 2013 Ryan McHugh who's here this weekend he committed the first code in GitHub for the WordPress rest API and then he continued working on that as a Google Summer of Code project in 2014 the first Version of the WordPress API API was done It was quite stable and robust, but there were a bunch of things preventing it from being included in the WordPress core Such as it not having its own internal API and being difficult to extend but it was good for Getting and manipulating posts and pages media terms so taxonomies and users So then in 2015 Version 2 was started So the main people working on that were Ryan and Rachel Joe and Daniel and they've been the main contributors to the WordPress rest API they added schemas which are essentially like documentation within the API, but they can also be used for other things like validating Information that you're trying to post to your site And then later in the beta one a controller class Was added which the controller class can be extended. So that's how you add add-on to the rest API to make Custom get get custom information back So if you say for WooCommerce they would have There they would extend the controller to add Products to the rest API so that you can not only get posts and pages but products too And then the server Was added which knows about all of the endpoints that have been added. So an endpoint is Essentially the end part of the URL that's how you get How you tell it what information that you want. We'll see more of that later and in so 2015 Development continued and through 2016 and finally in December 2016 the API was merged into core. So that was very exciting. Oh in 2015 the infrastructure was merged in which meant that It was getting ready to use it, but there weren't actually any end points So they still needed to be required a plug-in to To use them But now the full API is integrated. So it was very cool So who is using it a Bunch of plug-ins are already using it some of them previously required The rest API plug-in to be enabled, but now they don't so search wp is a plug-in that Fetches the information from your website onto their servers and processes it indexes it makes it a way better search Search information then WordPress has by default WordPress search mainly just Looks at the content and the title so Yeah, search wp And then so WordPress search returns The newest post first or the newest page first Whereas search wp has relevance and all of that sort of thing in it Tabulate is another plug-in. It's not dependent on the API, but it uses it for Enhanced navigation. So previously if you optionally installed the rest API plug-in then tabulate would enhance its navigation WooCommerce is Fully integrated with the API since version version 2.6. So that's pretty cool easy digital downloads another e-commerce plug-in actually has its own rest API but Maybe they will port over to the WordPress rest API who knows and then Advanced custom fields can also integrate With an extra plug-in There are a bunch of websites that are already using the rest API so We've got Us to Who make the game Monument Valley and there are Design development agency for games and such I believe they're using react to power their site on the front end Modern tribe are also using react to power the front end of their site. Also Guggenheim is Yeah, using the rest API to power some of their site but There's also custom Admin interfaces being built So on wordpress.com We're using What's what we call Calypso? And it's built with react and it's a totally new admin interface different to your regular WP admin and happy tables is a app for restaurants and it is Using the rest API also It's being used in mobile applications. So the main one is the official WordPress mobile app But Joe started to write Vienna using react native It's not anywhere near done, but if you are interested in being involved with Developing a mobile app for WordPress then That's a really good place to start. It also has some code Relating well, it's a good example of using the rest API with react native if you're interested in building your own apps for that Okay, so how do you use it? The first step is that you're going to need to find the uniform resource Location so there's a discovery URL that is now in the head of your WordPress site So if you look at the HTML of your site, you'll find it there But generally it's just your domain Slash WP dash Jason and then You need to construct the URL with the Endpoint that you want so to find the resource that you are looking for so most of the or all of the Built-in or default endpoints Located at WP slash V2 and then the one you're looking for so posts pages Taxonomies I'll show you them later and then so once if you say get That URL it's going to return Adjacent response with your posts and then you can use that information however you like So this is an example response So there's all you can also use query strings or provide More information in Jason format In your request So and you can also just put these URLs in your browser if you want to see the Jason that's returned So this is an example of me searching for CSS using the rest API on my website so you can see that the This is the first part of the response And the first post you can see ID date link title So that's returned Some examples of what you could do with the rest API So you could suggest search terms for your visitors. So they start typing in a search box And you could have a script that like starts Searching the site already for likely Ends of their searches kind of like what Google does You could use pagination so you could get the next set of posts Without having to reload the page you could Do an archive or portfolio filter so you could have an archive page and like, you know Just have buttons that say click on the year or click on the category and show those posts without having to reload the page You can pretty much replace your admin dash Ajax dot PHP tasks with the rest API So yeah, if you're writing plugins that use admin Ajax you can Stop because admin Ajax is kind of slow and resource intensive So Those are things on your site things that you can do in other applications you could search a site from anywhere So I use this to streamline my customer support workflow. So I will show you my Search script that I wrote in Alfred to be able to search our documentation and provide a link To a user really quickly In theory you could Make a quick post tool to your site. So I was thinking of writing Another script like if I have an idea for a post just Real quickly type in the title or the or a short description and it would create a draft on my site You can pass information into other APIs in Whatever other language you need. So stuff you could do is like integrate sign-ups on your website with sales force or MailChimp or something like that you could display real-time sales data or Real-time any data from your website if you had an event. So say you You know you're having a fundraiser and you were using WooCommerce or something like that to take donations you could Have on your screen the like real-time raising money so this is One example that I am working on using AngularJS and What I'm doing is building a website so people can order drinks at my house That might sound weird, but I have many many varieties of tea and I thought how awesome would it be if somebody can pull up on their phone My tea menu and Order tea and then it could come like the order could come directly to my phone and that would be awesome fun So this is the main part of the code that is using the rest API So I'm basically so I'm using the Angular the Angular method HTTP I am getting so Fetching information you can use post to post information, but then you need to authenticate so You need to basically log in to your site. There's various authentication methods Yep, so I am getting this is the development URL of my website Getting posts I've put in per page a hundred. That's the maximum that you can fetch at a time And I want to get all of them and I want to order by title because ordering by date makes no sense with tea and then this Adds all of the returned data to a variable Called drinks and I'll show you how it works If I can figure out This one on hello. Yep. Yeah, if I can figure out How to get out out of here and show you my browser Nope whoopsies Okay, so this is very much a work in progress It's ugly and There are some formatting issues that I am yet to address but but basically I Have the list of the drinks that are available at my house If somebody wants I don't have any hot chocolate listed right now I only have one kind of coffee right now But I have tea so if you want tea you can filter if you want a black tea or a green tea Or maybe you are feeling like something minty Organic peppermint sounds good. You can tap to get more information which is Still a work in progress and then you can add that drink to your order If you're ordering for multiple people Apparently no chai somebody white with rose sounds very floral and then yeah you pop in your name and Order so all of this information These are all posts in a WordPress install These are all custom taxonomies. So these ones are tags These ones are cat categories These are a custom taxonomy for variety And they're all fetched with Code like the one that I just showed you. I will put these this on github when it's More refined and has less errors But yeah, so you can see the example if you want to Where's my mouse? Okay, and so my search from anywhere is Currently a script workflow in Alfred. If you're not familiar with Alfred It is like an app launcher for the Mac, but way more than an app launcher. It's a Custom search engine you can like do calculations in it So you just have a shortcode you pull it up and it does magic things. So building a workflow in Alfred is like just dragging and dropping and connecting Operations together so in Alfred if I type sp And then something after that It is going to run my script and Then I can open the URL for that gets returned or I can Press shift to just copy that URL to my clipboard Here is the code. Oh, that's not very visible. Sorry about that I'll Definitely make this available as well but basically My rest API URL is Up there. I've got a bunch of like order by title Per get a certain number of results per page And my search term and then so this is a PHP script But you could do it in any language that you're familiar with Python is seems like a popular choice, but I don't know how to write that So curl fetches the URL and then this is XML that Alfred uses to list the results So I'll show you how that works. I think I'm actually gonna need to un-mirror for this. Hang on a sec or mirror Okay, so that's my Alfred shortcut is just Control space and I pull it up. And so if I type SP it Has a bunch of options so I could launch any of these other apps if I wanted to but what I actually want to do is search so I'm going to search for custom menu and It is Searching our support site on webpress.com In real time and returning that stuff through the rest API And yeah, as I said I can open the page Well, that's a bit unfortunate No, it's like the crazy whatever I did with the browser Did it again? That's the one that I wanted Let's search for something. I will search for menus again because menus are cool And then if I just wanted to copy something like Telling something about galleries. I don't need to open the page because I already know what it says But I can just copy that by pressing shift and enter So Yeah, if there's something that you repeatedly do Interacting with a WordPress site on a day-to-day basis you can make a custom script in Alfred or you could run that you could run that from anywhere You'd run it from the command line if you like, okay That is the couple of images that I Creative comments images that I took and Thanks, are there any questions