Good day everybody, it is Thursday, it is Let's Code Thursday. Welcome to this online workshop. As you are joining, please do let us know in the chat where you're joining us from. And then please share a little bit about what you do with WordPress. I'm curious to know what your involvement is with WordPress. Do you use WordPress for work? Do you contribute to WordPress? Do you do both? Do you just use it for personal sites? Please let me know in the chat so that I can sort of get to know where everybody's from and what everybody does in and around WordPress. While you're doing that, I will do my usual introductions. My name is Jonathan. I am from Cape Town in South Africa, which is right at the bottom of Africa. I am currently a developer educator at Automatic, and I am sponsored to work with the training team. The training team are the group of folks that primarily work on learn.wordpress.org. We create tutorials, we create lesson plans, we run these online workshops, we create courses, and we also try and fix bugs and improve the Learn WordPress platform. So that's my bit. Welcome, Adrian, from Southern California. Adrian says, I use WordPress for small client websites. Great. Welcome, Bud. Bud is from Nutley, New Jersey. Bud says, always learning new stuff to help me create WordPress content for WordPress businesses. Excellent. So welcome to Adrian and to Bud. We've got a few other folks joining, so I'll let them sort of start feeding through their information. Sergio says, hi all from Washington state. I do some development plugins, et cetera. Excellent. Welcome, Sergio. You are my people, and I support WordPress sites for non-profit. Bud says, love your presentations. Thank you, Bud. I appreciate that. I am hopefully getting better over time. I was thinking about this the other day. I remember my very first online workshop and I was very, very nervous because my presentation style, if you will, is built around doing things in person, interacting with people in person. And so the first time I did an online workshop was very daunting for me, but I feel like I've gotten comfortable with them now. Spelling defy doesn't count, you're correct. We don't worry about spelling in these workshops. Cynthia says, hi from Ontario, Canada. Hi, Cynthia. I use WordPress every day as a developer and maintain client sites for an agency. I care. I'm also a WordPress educator and contribute to learn.wordpress.org. That is correct. Cynthia, if I'm correct, this is the correct Cynthia. Cynthia recently, yesterday, in fact, had her first pull request merged to the Learn.wordpress website. So she submitted a pull request to the platform fixing a bug with the search field if I'm not mistaken. And so that was quite exciting to go through that process with Cynthia. So welcome, Cynthia. All right. Please, as you, as you're coming in, please do continue to, to let us know where you're from. I'll hop back into the chat to read out any more answers that might come through. It's always lovely to know where people are from in the world and what they do with WordPress. So if you join, please let us know where you're from and what you do. I'm going to continue along with my little presentation here today. So today we are going to be focusing on the HTTP request API in WordPress. The eagle-eyed among you may have noticed that when I originally posted this on Meetup.com, it was just called the HTTP API. And then in preparing the slides for today's session and preparing the work for today's session, I realized that that was slightly incorrect. And I am a stickler for naming things correctly. So I updated it to HTTP request API. And I will dive into why I did that as part of my slides, because I think it's important to understand these different terms and these different namings. But that is what we're going to be focusing on today. Just reading some more updates. Elliot says hi from Cheltenham, bit of a veteran. I've been using WordPress since 2003-2004. That's way more than me for bespoke business websites, developing for custom themes and plugins. Meetup organizer from my local community. And I plan to contribute more to WordPress as and when I can. Excellent. Welcome, Elliot. Stefan says, glad to be here from Sydney, Australia. Sydney, Australia. Is that right? Wow. Welcome from Sydney, Australia. It's quite late there in the evening. It's not all quite early in the morning. One of the two. 12.05 AM. Wow, Stefan. I am honored that you are up this late. Hopefully you've got something to keep you awake. I used to be a midnight owl, but as I've gotten older, that's not something I can do much of anymore. So welcome. Stefan says, been using WordPress since 2017. Happy to connect here. And he's shared his LinkedIn link in the chat. All right. Okay. Before we get into the meat of today, let me deal with some announcements and I just need to make one small change. Thanks to Assad, who is co-hosting with me today. Assad let me know today that he was available to co-host and so I didn't have time to update my slides. So there we go. I'm updating them now. So welcome everybody one more time and thank you to Assad, who is co-hosting today. It is his ninth co-hosting session. So the next time he co-hosts, you will have co-hosted for 10 times. So please give him a big, silent round of applause for that. It's always great to have regular co-hosts who I don't have to train. Assad just knows what he needs to do and he gets on with it. It's great. If you have joined and you can't see my slides right now, I am sharing my screen and you should see an announcement slide on the screen. If you can't see what I'm presenting, please do let us know in the chat. There is a minor not back, but it's a little glitch with Linux systems where if you join and I'm already sharing, sometimes you won't see it. So if you if at any point in time I am sharing, I'm sharing my screen the whole time during the session. So if at any point in time you can't see my screen, please do let me know. There we go. Sergio says constantly sites perfect. So let us just reset that. So I'm going to stop the share. And then I'm going to move some windows around because things overlap other things when I stop the share. And then I'm going to share my screen again. And then Sergio, if you could just give us a thumbs up or a yes or a can see if you can now see the screen. Then we know that it's all good there. Great. Okay. Then a note that we are presenting in focus mode. So that means that I Assad and I can see all of your video feeds, but you can't see each other. This is just to protect everybody in the in the workshop. We have had some issues of zoom bombing in the past. Thank you Sergio for confirming. So just to prevent any possible zoom bombing. If you would like to enable your video so that Assad and I can see you that is up to entirely up to you. You don't have to. But if you want to, you are more than welcome to. And while we're saying that I'm going to say hi, Adrian, I can see you there. So thank you for enabling your video. You are always welcome to ask questions in these sessions. Something that my colleague Ben, I was, I was fortunate to be an attendee this morning. My colleague Ben, Ben, who works with me in the training team, he presented a session this morning at 10 a.m. my time and I was able to be an attendee and that was wonderful just to sit and watch and learn along with other folks. Something that he reminded me of is the fact that we want these spaces to be safe for our attendees. And so that's why we have the focus mode. We also wanted to be a learning experience. So it's an open, open opportunity to ask questions in the chat. If you have any questions, if you don't like to use the chat, I don't mind which way you ask questions. Chat tends to be easier for folks because they can ask questions while the presentation is happening without interrupting me. But if you prefer to do it via voice, if you, if you don't want to type your questions, you're welcome to unmute as well. There is a little raised hand reaction that Zoom offers. You can raise your hand and then Assad and I will pick that up and we'll, we'll give you the opportunity to speak or just unmute and just go excuse me. There are no, you won't get into trouble for interrupting me here at all. I won't be upset if you do that. The only, the only request that I do have is if your question is unrelated to what we're presenting at the time, if it's maybe off on a tangent, maybe keep that I do allow breaks for sort of tangential questions. So keep it for that moment in time and then ask it then, or otherwise just post them in the chat and when I take breaks will follow up on those questions and get answers for them. All right. If you would like to code along with me today, so these sessions that I run every Thursday, we generally have a live coding portion. If you want to code along with me, please do get your local WordPress installation up and ready. There are a couple of other requirements, but I'll dive into them in a second. And then, as always, I do tend to speak fast when I get excited and I get excited when I'm presenting. So if I'm going too fast or if I'm rushing something, please do let me know you can shout in the chat or you can unmute and ask me to slow down, and I will slow down. If there's anything on screen that I'm jumping too far ahead too quickly, let me know and I'll pause it or share the link in the chat so that we can all catch up. Lastly, this is being recorded as mentioned at the start of the session. So the session is being recorded and is being uploaded to WordPress TV afterwards. So if you have to leave early, that's fine. You can catch the rest of it on WordPress TV. I usually do it the Friday or the Monday after my Thursday session. If you're looking for more learning WordPress resources, you can go to learn.wordpress.org. And then if you're looking for more developer focused news, you can find that at developer.wordpress.org slash news. This is a fairly new-ish blog that has been launched right about the beginning of this year. And there are some great articles there, all developer focused articles. All right, does anybody have any questions, comments, anything they want to say before we dive into what we're going to be talking about today? I'm going to grab a quick sip of something to refresh my voice and then I will move on. Okay. Sergio says, will WP now work for the presentation? Yes, if you've got WP now up and running and you want to use it, that's perfectly fine as well. We're basically going to be working inside of one plugin file. So as long as you've got a WordPress install that works and as long as that WordPress install can make external requests. So sometimes local development environments have like a closed network, not all of them. But generally, if you can't make external requests, you'll get that error about your site can't connect to the WordPress.org service, which I sometimes have on the Learn WordPress code base. But anyway, but WP now should work perfectly fine as well. Okay. Our learning outcomes for today, as I mentioned, we're going to be diving into the HTTP request API. First, we're going to define what we're talking about when we talk about the request API. And then we're going to dive into some terminology because when it comes to APIs and API HTTP REST request, what do these things mean? So I'm going to cover some of that terminology with you. Then we're going to look at how we can use it to fetch data from an external service and how we can use it to send the data to an external service. We're also going to briefly touch on performance considerations when it comes to sending and receiving data outside of your WordPress site. And then we're going to briefly cover some advanced REST API topics. When we're doing the fetching and the sending, that's when we'll be doing the live coding portion. And then the performance and the advanced topics will be more of a theory behind how those things work. Everything is documented on the WordPress developer documentation. So everything is there and I will be sharing the links with you as we go along. Then lastly, before we kick off, what I'd like to ask is on a scale of one to five, how well do you feel like you know this topic? So one being you know very little or next to nothing about this topic. You've never even heard of the HTTP request API. Five being you are a request HTTP request king. You are making requests and sends and gets and posts. And you know all about these things.  If none of those terms mean anything to you, you're probably a one. If they all make sense to you, you're probably a four or a five. I consider myself a four in this in this area. I have done quite some extensive work with the WordPress HTTP request API. While folks are leaving their scores there, I'm going to share a public link. I've shared this before this plugin in the chat. It's a seriously simple podcasting plugin. It's the plugin that I effectively. I wouldn't say cut my teeth on when it came to API extensions, but specifically API extensions or API integrations for WordPress. I cut my teeth on this project in this plugin. We built a API as part of the app service that we were building. And then we had to build a API connection from the plugin to the. I'm trying to find it now to the API. So I had to build an entire what I call the cast us handler, which connects to the API sets up tokens and all those kinds of things. So if this is an interest of you to see how something like this would work in the real world, I'm going to share that link with you. We're not going to talk about it today, but it's just one way that it could be implemented. I'm not saying it's the best code in the world. Definitely not because I wrote it. But it's something that you can have a look at if you want to see how, how things, how things might work in the real world. Okay. Adrian says she's a one step and says to Zania. I hope I'm pronouncing your name correctly. They're one. So just is to Bud says I'm a zero point five. Thank you. But Elliot is a three to four. That would make sense because he's working with those kind of things. Sonia is a two. Cassaba says three. Okay. So we've got a good range of folks. So that's excellent. So hopefully for the fours, the threes and fours, you learned something new today. If not, maybe it's just a good refresher of, of how it all works. All right. Then let's talk very quickly about requirements for today. If you want to code along first two requirements are local WordPress install in some kind of text editor. I use visual code studio code just because it's one of the most popular free open source code editors that folks can use. I use it for my presentations in my day today. I actually use PHP storm, but I'm using VS code today. Then I did a little bit of research. And I was looking for an API that we could use in the session. And if anybody's watching this recording afterwards, that doesn't require us to have a working API. You know, you'd have to have some kind of app that you sign up for like the GitHub API or a stripe API or something like that. And I found this lovely API called fake store API.com. And what that essentially is, is a fake store API. So, and we'll talk about APIs in a second and the terminology and all of that, but it's a free rest API that you can use whenever you need pseudo, pseudo real data for an e-commerce or shopping website. And it even has a homepage. It has documentation that you can go and read just like you would any other API service from any other kind of product. You can create requests to get all products, get a single product by the ID. You can limit results. It's really amazing for testing. So we're going to be using this today. So if you're going to code along with me, keep that open. We're just going to be doing one or two API requests, but it's a fun one to use if you're busy testing your knowledge around how APIs work. The data that you might be sending doesn't get stored anywhere, but it does give you a result that you can then work with. And if you do an update or a delete, it'll give you some kind of data. So that's really, really cool. I thought and a handy tool to use if you're a busy learning to develop with HTTP requests. And then finally a test plugin. So I have just set up a very simple plugin. I'm going to share the link with you in the chat. I haven't created this as a download because we're going to create this plugin live. So I haven't made it a downloadable plugin, but this is the code we're going to be using. You'll see it just sets up a sub menu page or admin menu page. And then the page itself just has a thing for products. It has an action hook in it. And the reason I put an action hook in is because I want it to be able to hook something into a hook and then keep the code that we're working on in one place. So that's going to be in this learn products data function. And that's where we'll be doing our HTTP request today. So if you want to, I'm actually going to do that now. So you can watch me do it. You can just hit raw. And that'll give you the raw PHP code. You can select all of this. You can then go into your text editor or however you want to create the plugin file.  And I'm just going to call mine WP learn HTTP API dot PHP, just to keep it super, super simple. And I'm just going to paste that code in. Now my, my VS code has given me a couple of red lines, which are not huge areas. I'm not going to worry about them too much. I'm also just going to format this code. So it's a little bit better following WordPress coding standards. But once that file is created in your plugins directory, you should then be able to enable this plugin in your WordPress site. So if I now go over to my local WordPress install, this one is my learn press site. So I'm going to open that. So learn press dot test. There's the local domain that I have. And wow, that's, that's really zoomed in. I don't know why that is. Let's just reset that. I must have been zooming in for things the other day. So I'm just going to log into my local WordPress install. And I'm going to activate this plugin. So if we go over to plugins, there are, okay. Akismet needs an update. I'm not worried about that now. There is the learn ACP API plugin version 001 learning about the API. I'm going to activate it. There it is. There's the admin menu. And if I click on it, it's just an empty page in my admin dashboard. Okay. So if you're still busy with that, I'm going to pause for a second, grab another sip of coffee before we continue. If you're ready to get going, then give me a thumbs up or an okay or something in the chat. And then we will start diving in. It looks like everybody is good to go. So thank you very much for that. If you're not ready to go, you can let me know and I will slow down, but let's start diving into things. One of the things that I've just realized, I usually share my slides beforehand so that folks can copy paste these links from the slides. I forgot to do that today. So I apologize. What I'm going to do is I'm going to share these slides quickly now with you in the chat so that you can open them on your side if you would like to. I'm going to say anyone can view. And I'm going to copy that link and pop it in the chat. And then I will do the usual upload of the files to the slide share and share it and meet up afterwards. But if you want to copy and paste the text, the links that I'm working with, you're more than welcome to. Right at the bottom of these slides, I always add a resources tab. So that's there if you want it. And I'm going to open up the one, two, three, four fifth link here. And I'm going to share it with you in the chat so you can open it up there as well. And this is the documentation in the developer documentation on WordPress.org in the common API section about making HTTP requests. And basically it says here very often we need to make HTTP requests from our theme or plugin. For example, when we need to fetch data from an external API. Luckily WordPress has many helper functions to help you do that. And those helper functions are basically what forms part of the HTTP request API. And there are some examples of how to do it on that page. Now, before we dive into all of that, I want to go back a couple of slides. Just after the let's go slide, there is a terminology slide. And I'm going to make this a little bit bigger so we can all see it. And I want to dive into some specific words and make sure we understand what those words mean. So an API is an application programming interface, which is a set of functions and procedures that allow one application to interact with each other. So any way that you could interact with something else is considered an API. So if you have used the register post type function, or if you have used the add action or add filter functions in code snippets, those would be considered an API because you in your plugin or your theme, one piece of software, are interacting with WordPress core, another piece of software, and doing something between those two pieces of software. The thanks of the matter is your plugin, you can use it as a side of WordPress. Sure, I understand that, but it is essentially the same concept. It's an API, it's an application programming interface. HTTP is what's known as the hypertext transfer protocol. And this is essentially the protocol that the internet runs on. So when you go to a web browser, sorry, a website, you will probably know that your actual URL is either HTTP in the old days before we had secure certificates, or it's HTTPS. So it's using the HTTP protocol to send and receive that data. It is kind of the backbone of how the internet works. And if you open up a URL, I'm on learn.wordpress.org now, and you open up your developer tools in your browser, I'm not going to ask you to do that now. If you know how to do it, please go ahead, but otherwise just watch what I'm going to show you here quickly. And if you have a look at the network tab in your developer tools, I'm going to refresh this request here. Let's go right to the top, there it is there, and I'm going to zoom in on this. Why can't I zoom in? Okay, let's do it this way. No, that's not... How do I make this bigger? It doesn't look like I can. Anyway, so the request that I made was to the learn.wordpress.org URL. And it is an HTTP request. So if I have a look at the headers, the request method is a get method. So a get method means fetch some data. I get a status code or a response code of 200, that's a default of an HTTP request, and then there are things like remote addresses and the response headers and all kinds of other things. Then there is also a response. And in the case of a website, the response is generally HTML. So any kind of HTTP request makes a request to the server. The server determines what type of request it is, if it's a get or a post or whatever. And based on that request and based on the data that is sent, it returns some information. In the case of a website, some HTML. So that's when we talk about command plus and minus. Thank you. There we go. That's what we're talking about when we're talking about HTTP and when we're talking about requests. So anything across the web is usually HTTP and request is when you ask the server for something. Okay. So then when we talk about an HTTP API, we put those two words together. An HTTP API is a set of functions and procedures that allow one application to interact with each other using the HTTP protocol. So a web request is a form of an HTTP API. I hope that the captions are not stressing with my quick pronunciation of HTTP. But essentially any system that allows you to make a request and receive some data is considered an HTTP API. You get different types of HTTP APIs. You get some that respond with SOAP responses. SOAP is an XML format. You get some that respond with REST responses. We'll chat about that in a second. You get some that respond with HTML. So a web request, but they're all kind of HTTP APIs. Then if we move on to the next page of terminology, here we start talking about REST. So REST is known as representational state transfer. And it's a style, an architectural style or a software style that defines a specific set of constraints for creating web services. So in REST, they normally talk about you have to have, you have to use the GET request to fetch data. You have to use the POST request to add data. You have to send up, I think it's a patch request to update data. And then you send a delete request to delete data. And generally a REST HTTP API or an HTTP REST API will use JSON formatting as your data that gets sent back instead of HTML. So when we talk about an HTTP REST API, it means a set of function and procedures that allow one application to interact with each other, the API part, using the HTTP protocol, the HTTP part, and then it uses the REST architectural style. And it's more commonly known as a REST API. So the full name should be HTTP meaning it's going across the web, REST meaning it's the style of service and then API meaning it's this application programming interface. But folks will often shorten it to REST API. Now, probably wondering why am I bothering to tell you this? Well, it gets back to the wording that I was mentioning earlier when I started putting together this workshop. I referred to what we were going to learn today as the WordPress HTTP API, which it's not. It's an HTTP request API. So it's across the web. It's an application programming interface, but it's for requesting data back and forth. As I said in the previous step, an HTTP API would be a set of functions and procedures that only allows one application to interact with the other using the protocol. So it's good to understand the differences. However, this page, this making HTTP request page, if you go back and look at it on, this is how I remember it when I first saw the page, it actually said HTTP API. And I think because of that confusion of terminology, they've updated this page to just say making HTTP requests because that name wasn't 100% correct. Now, I know this is me being super pedantic and super sort of sticky about naming, but I just wanted you to know the differences of what the different terminologies mean. And sometimes if you said to somebody HTTP API, they might assume REST API. And sometimes there's confusion. I remember presenting a talk about the WordPress HTTP request API and somebody said to me, but why are you talking about that? There's documentation and it's REST and it's this. And I said, no, no, no, you're misunderstanding what I'm presenting on. So there's some confusion even in the developer community about what is the REST API versus what is the HTTP API versus what is the request API. So that's why I'm referring to this as the request API because it's the API used for making HTTP requests. Okay, I hope that wasn't too much of information, but I just thought that was useful to get out of the way. All right, any questions around that? I see Elliot says, and sometimes REST is authenticated as well in public. That is correct. Sometimes not, sometimes completely open. Yeah, developer world is a minefield of acronyms and abbreviations, and it can sometimes get very, very confusing. Awesome. Okay, thank you, Felipe, for that. All right. So then let us move on to what we're talking about here. So when we talk about making requests to an external service, we're talking about something like this fake store API you might be wanting to connect your WordPress site to Stripe using the Stripe REST API. You might find, and this was actually my niche when I was a freelancer, I used to look for projects where the client needed a specific API integration that didn't exist as a free plugin on WordPress.org or a paid for plugin either. So they were using some third-party service that nobody really was using, but they needed it for their company or they were using some newsletter platform that wasn't very popular, but their enterprise service decided to use it and they needed to interact with their site. So that was my sort of niche. I enjoyed doing those kind of projects, and that's why I spent a lot of time working with the HTTP request API. It's a lot of fun. It's interesting. It's also the one area of development where unless you have a good set of tools to do testing with, things can get confusing because you're essentially in a page request or in an admin page request, you're having to make some external request. It's going to do something that you have no control over. It's going to return some data and then you have to make sure that you have that data and you know what's going on with that data. So it's fun. To me, it's a fun type of development. So the first thing that I want to do is I want to show you how you can use the request API, the HTTP request API to fetch data. So if we have a look at the get all products endpoint in our Faker stored at API, the URL that you would use to fetch the information is Faker stored at API slash products. If you pop this into a browser, you will see and in my browser, it's probably a little bit neater than maybe yours because I have an extension installed. I'm going to switch it to raw. You'll probably see something like this and if you view the source of this in the browser, you will see that it's just a line of text. But if I take this text and I'm going to paste it into something called JSON pretty, which is a... I don't use that one. I use, which one do I use? I don't see the one that I use because it's not highlighted for me. Let's use JSON pretty print. Basically, this is a tool. You can paste some JSON content in here and then you can hit make it pretty and it then shows you... Okay, I'm going to have to go to the mind not working. Here we go. And it shows you a tidier version of this JSON response. So if you've never seen or heard of the word JSON before, JSON is basically JavaScript object notation. It's a JavaScript definition of how we would formalize and structure data to be sent across REST APIs. What's nice about it, it's a string, so it's lightweight, but it uses a specific format. It uses the square brackets, the parentheses, and a certain format for transporting data back and forth. So the nice thing about FakerStore is we can test that the get endpoint works and by making this request to the FakerStore API products URL, we are actually making an HTTP get request. As I mentioned to you earlier, if I hit developer tools here, let me switch off my browser window, I don't know why that's on. But if you have a look in the network tab, let's refresh this again. There is the URL, FakerStore products. There is the get request. It's responding with a 200, which means we're happy with that. And you should be able to use this for any public HTTP API. You should be able to pop it into your browser. Your browser will make a request and you can get that data back. What we would like to do, as we would like to do this programmatically, we would like to fetch these products and somehow store them or display them in our WordPress site. So if you have a look, if you go back to the documentation that I showed you, you will see the very first item after making HTTP requests is getting data from an external service. Getting or fetching of any data, we use the WP remote get function. So this function performs the request with a get method and then returns the response. That's all it does. So just like the browser, you make the request, you send it the right verb. It responds with the response and then you have to work with the response. So let's do that. Let's do that in our plugin. So in my Visual Studio Code, in the learn products data area, which is going to fire just after the products page, I'm going to simply do that. I'm going to say data equals WP remote get and I'm simply going to pass in, and that's not what I want. I'm simply going to pass in the URL. There we go. And then just to make my life a little bit easier, what I'm going to do now is I'm going to print R, which is a PHP function, which will just print out all of the values in this data variable. It's going to look nasty. Don't worry. We will fix it up later and just pop print our data in there.  So one there and then one at the bottom here. That's all I'm doing. I'm also going to make sure this code is neat and tidy and then I'm going to copy this out and pop it in the chat so that you can copy that on your site if you need to. I see that Sergio and Felipe have shared the status codes. Thank you for those. We will dive into those status codes in a second. But this is the code we're working with. So this is just a very simple, get the data from products or sorry, get the response from products, pop it into the data variable and then just print out that data variable on screen. So that's all I want to do now. Let me show you what that does and what that looks like. And it's a whole bunch of stuff. So let's dive into this whole bunch of stuff quickly and see what we're getting when we respond, when we get the response from the request. So we receive an array of information, which is great. We can work with arrays. The first item in the array is the headers. So if you remember when we were looking at the request in the browser, there are always headers that are getting sent back and forth in any request. There are certain hidden bits of data that gets sent back and forth. The server will read those headers and do something with them possibly. And sometimes when the server responds, there are certain headers that are useful. We'll talk about those in a second. So there's always headers in any kind of request or usually. And the headers are various things. They've got the date, the content type, various other things, what type of server this is running on. So we can see that the server we're requesting from is running on CloudFare. That's interesting. And various other bits and pieces of information. Then there is the body. So the body is typically the data. And as you can see, it's that JSON string that we looked at earlier. So that's typically the data that we're going to be working with to be then displaying it wherever on your site. There's also a response item, which includes the response code and a message to say, in this case, all good. If it was anything other than 200, if it was an error, then the response would be something else, either you don't have access or the server is done or you're not authenticated. All of those kind of messages are usually sent back in the response. And then there's additional information, like if there are cookies in play. There's also an HTTP response object. So this is the response object that is used to make this request. This is stored in the response as well. And you'll see a lot of the data is duplicated here. And then it closes that array. So that's primarily what's sitting there. The most important things you need to worry about as your headers, if you need to read them, your body, which is your primary source of data, and then your response information, if you need to know whether things are happy or not. So any questions about how to make a request to an API using WP remote get before we continue. As you can see, it's very simple. It's one call. And then you get the data and then you can do something with it. Any questions on that before we dive into the, well, what should we do with it? Which would be the next question. Okay. Sonia says all clear. Thank you for that. If anybody else wants me to stop and slow down, let me know. Otherwise we will continue. So the first thing that you want to check is you're going to want to check what my status code is. And Sergio and Felipe were very kind to share the status codes with me. I was just going to go and find one on the internet. So I'm going to go with Sergio's one, which is on the Mozilla docs site. Mozilla is a great MD and docs is a great place to learn about web development. They have all the requests there. So you will notice that a lot of these requests are sometimes, these status codes are often codes that you will see when you're just browsing a website and you'll see something 500 error code. You can actually come here and you can see what's going on, what's broken. So 400 is a bad request. There was a problem with the request that you made. Maybe you passed the wrong dates or whatever the case may be. 401, for example, is unauthorized and so on, so on, so it goes. So the first thing you're going to want to do is you're going to want to check your status code. And you're going to want to make sure that your status code is, and I just want to see if I can find it in this page. There's 200. So 200 is your, it's okay. Everything's good. Nothing went wrong. We're happy and you've received the data you need to receive. So generally what you can then do is you can use a function which I'll share with you now. Let me just open it up here in the documentation. You can use a function called WP Remote Retrieve Response Code. And you can use that on the response that you receive from the request. And that will return the error code itself. So, sorry. I'm sorry. I'm jumping around on my screen here. So you can literally do something like this. You can say code equals wrong one. Let me just copy it again. It's in my notes. WP Remote Retrieve Response Code. And you pass it the data response from your request. Now, if you happen to have come from another platform, another CMS, maybe even a PHP framework, maybe you've used something like an HTTP client, a PHP HTTP client like Guzzle or one of those. A lot of this is built in for you. So when you use the default methods there, you can just call another method and get the response code back quickly. If you're building in a WordPress plugin, you kind of need to use some of these functions a little bit manually yourself. You'll notice in that class that I shared with you earlier, some of this I've kind of automated. And when the response is made, I automatically pull the code out and put it into a variable so I can check it later. I can't repeat myself as I keep making these requests. And so the first thing you might want to do, and again, there's no right or wrong way here. But what you might want to do is you might need to check, well, is the response code 200? The other thing that you can do, though, is you can do something like this. And this is something that I've seen in projects and I recommend this as well. You can use the... Sorry, let me just go... You can use this function called the isWPError function. Now, what this will do is let's say you've called something wrong in your WordPress request area. Something's gone wrong somewhere. And it might return an error before it even tries to make the request. Then you can use that and you can say, well, is there a data error? Let's actually change these variables quickly.  So I'm not getting data back. I'm getting a full response back. So it's a response from the server, which contains all that information I showed you on the screen. And one of the first things you might want to do, you might want to say if isWPError response. So if some WordPress error happened before the request could even be made, maybe there was something misconfigured somewhere and then you can output some kind of message and say there was an error on the site or there was an error that happened somewhere or something. And then you don't even have to worry about checking for the code because the code wouldn't have happened. The status code wouldn't have even been returned because the request couldn't get made. So that's the first thing I like to check. Was there some kind of WordPress error when I was trying to make this remote get request? And then I might just do something like say echo an internal WordPress error happened that prevented the request from being made or something along those lines. However, your software situation requires it. Then once you've done that, then it's a good idea to get the code because if there wasn't an error it probably made the request correctly and whether the request response was good as up to whether the server sent it back or not. So that's a good idea to do the code check. And then you could do something like this. You could say, if and you would say maybe 200 is not equal to the code and I'm actually just going to do this as well. I'm going to just return here because I don't want it to continue after that. So then you could say something like if the code was not equal to 200 then again you could say echo the request was made but an HTTP error and then you might also want to add the error code to the message so that the person knows which error happened and they can then investigate further and I'm just going to return there. Okay and you might want to do more with that information. I'm just seeing it's giving me an area here and I'm trying to figure out why this is an escaping function. That's why PHP CS is being very picky to me today. So that's the next thing that you might want to do. You might want to check well if there was an error sorry if there wasn't if the code was 200, what wasn't 200 then an error happened. Sorry I'm getting myself confused here and the cool thing is then you could also do something like this. You can say you can do this you can say echo response and you can say get error message um like that is that right? Yeah it's giving me escaping function issues again. So you can actually get the error message if you remember we looked at that earlier it was yeah you can get the message and then display that message to the user. So that's another good thing to do is actually show them what happened and why things went wrong. So that's the next thing you could do. Once you've done that then you're probably pretty sure that things have gone right. You've checked for WordPress errors. WordPress errors didn't go wrong. You've checked for response errors um and if there were errors error codes were not 200 you displayed that. So now you can probably start working this working with this but you're probably not going to need the whole response. You just need that body and WordPress has another function that you can use which specifically will get the body from um from the response. So let me just uh get there quickly and we'll say retrieve body so WP remote retrieve body will take any HTTP request response object or a ratio I say and then retrieve the body from that so what we can do now is we can say okay fine the actual data that we want to work with and it's probably we know it's product data from the documentation so we can say product data equals WP remote retrieve body and then pass in that response um I see there is a question Elliot I will get to a question in a second I just want to finish this up so we can actually see it working and now we have that data and if we have a look at the data that we get over here where we remember that oh yes this is JSON so we're receiving JSON data so we might need to do something with that JSON so that we can work with it um and in WordPress land there is a JSON or at least in PHP land should I say um yeah this is a PHP function not a WordPress function silly boy um so in PHP land there is a JSON decode function so JSON decode takes that JSON string and converts it um and returns it as let me just check here it will return it as the as the relevant type um you can set the second parameter um associative will return an associative array when false it will return an object um so if you don't specify that second parameter as true you're going to get an object back and you're going to have to use object notation to export your data which I will show you now so if we go back to the code there is our product data um in fact that's not the product data I like that's just the body that's just the body which contains the JSON string the product data is actually the JSON decoded body um so we would go product data equals JSON code um and we decode the body so that's that and now we should expect that product data and I haven't tested any of this yet so this could go wrong and we'll fix it if we need to live but we would assume now that that's probably going to be the product data it's going to be in an object so I'm going to pop this into a div quickly I'm going to update this to pop it into a div I will share the final code with you um in the chat and then we might want to loop through this product data so we could say for each product data not that one sorry folks for each product data and we will say something like as product uh let me let me move this up so if anybody wants to see this on screen they can uh there we go and then we can just loop through the product and we can say okay fine let's just start with the product let's say um let's have a look at the documentation I can't remember what the fields were um there it is so if we get all products the output will be it'll be an ID title price category so let's go with title and price for now so we will say product title and you'll see there I'm using the object notation which is a little arrow um let's wrap the title in some kind of html so it makes sense when it displays otherwise it'll be all over the place um actually maybe that should be a header tag for correct semantic html I'll make it an h3 just for the sake of not being a paragraph and then I'll do the same for um the price we'll pop that into a paragraph tag and we'll say product price and then we will close that alright and then that should give us the product title the product price in our in our page let's leave that on screen let's do a quick test and see if that did work so let's do a refresh here if it all went well it should work and there we go we're getting the titles, we're getting the prices for all the products from the api um okay Elliott said doesn't get error message belong to the isWPError function um getErrorMessage um so let me let me just confirm that quickly so what I'm going to do um is I'm going to do do do do do actually Elliott your question is timely because the next thing that I'm going to talk about is how we would answer that so give me a second on that one if you don't mind um there's something I want to show you this is how I tend to develop with these things and then that'll help us answer that question so thank you for that question we'll dive into it in a sec um does anybody else have any questions around this code let me share it in the chat in case anybody wants to copy it on their side um so that they can they can try it out if they want to but essentially as I said you make your request you get a response back you're then going to check if the response had an error and someone says I've closed my three tags incorrectly thank you for pointing that out uh PHP storm is nice when I change the first one it changes the second one VS Code doesn't do that for me so as I was saying your first thing is you want to check was the response was there an error a wordpress error in relation to the response so something internal inside wordpress went wrong somewhere if not get the get the response code and then test the response code if it was a 200 great move on if it wasn't maybe show an error to the user um and then and then get that error message um we'll test that error message thing in a second it is and then uh once that's passed then you should be good to go uh and then you can say you can get the body because the body is usually going to be the data that you need to work with uh and then depending on the body's contents whether it is xml it's usually going to be some kind of string format either xml or json um soap is essentially a format like an extended version of xml but it's going to be one of those or something it's not going to be like a full html response um you're going to get that body back you're going to do whatever decoding you might need to do and then you could loop through that data and display it on your page okay i'm going to grab a sip of water before we dive into elliott's question sip of water sip of coffee maybe i should have water the coffee might be making me fast uh and then we will move on so as saab mentioned to me that i've set this workshop for an hour and a half and that's because there's a lot to get through today so i'm glad we have that extra 40 minutes um if anybody needs me to slow down or stop or whatever do let me know but i'm going to continue along so that we can get through everything okay so elliott's question was around isn't the you know get error message supposed to be on something else and this leads me into a the next thing that i want to share with you and that is debugging your your responses so one way to do it is using that print r that i showed you earlier and getting it on screen the problem with that is you then have to code that into your code then you have to show it on screen then you have to remove it to hide it or whatever the case may be um there are other ways to debug this information uh you can use things like xd bug and those kind of tools but one of the simplest ways that i found to do this kind of debugging and i'm sure elliott will uh zahiris is going to resend the code sure let me do that quickly um elliott well i'm sure oh wait someone's already done it thank you agent elliott will appreciate this is to use the wordpress debugging log um and i saw elliott actually tweet my the way that i do my debug logs uh recently so thank you for sharing that with folks but if you go into your wpconfig file and some of you will remember that i've done a session on debugging in wordpress before there is this wp debug constant that you can set true or false the way i like to work with my debug log uh is i can in in wordpress you can define whether to switch debugging on or off but you can also tell it to log any errors to a file and not display those errors on the screen so i like to use that so i use the following i use define wp debug true and i'll pop this in the chat now as well i define wp debug display as false meaning don't show the errors on screen and then i define wp debug log and i define the path to a logs directory inside of my wordpress install so i physically go and make that logs directory uh i will make it now here quickly and then the log file is debug uh dot sorry and then i pinned the current date in this format year month and day uh because i follow the the year month day format not day month year or month day year whatever it is so i always put the year then the month in the day and then dot log at the end and what they'll do is every day that i start new development it creates a new debug log file um so it's a nice way of not letting your log file become huge hugely big and crazy and when you're working today it's everything's in one today's file and then tomorrow it's a brand new file and you can start fresh so that's what i use in my word in my wp config to enable logging to a file i make sure that folder is there and i make sure this is set up past that folder this path over here i use a local um a buntu virtual server so that's why the path is the path on the virtual server not on my local workstation so my local pc so depending on how your environment is set up you might have to tweak that path if the path is on your local pc you'll have to put in whatever that path is if it's on a virtualized system something like docker maybe wp now one of those you're going to have to set that this actually goes back to um i think it was surgeo's question about using wp now i actually don't know how to set this up in wp now that you can enable the debug log in this way uh so this part might not work for you surgeo's i think it was surgeo's that's how i apologize if this doesn't the rest should work fine and then when you're working with your code you can use the php error log function um so error log is basically a php function that just logs files to whatever the defined log error log is in our case it's that debug log file and you can use that print r function that i showed you earlier um and then you can pass in whatever data you want be it an object be it an array be it a string be it whatever as long as you pass in the second parameter of true and what that does is returns it as a string which will then output to the log um what you will also notice is that because we're doing it this way we don't have to worry about those p re tags it'll be formatted nicely in the log file as well so that's what i'm going to do here i'm going to error log the response for this one so that we can then look at the response it'll be a copy of what we saw earlier but then we can see if there are any methods there uh what i'm also going to do is i'm going to do this um and bear with me while i'm doing this uh get class methods there's a php function called get class methods and you can pass it an object and it will return the methods for that object and that'll tell us whether or not this get error message method exists on the response object um so i'm going to make that true as well and then the other thing that you can do when i do like doing this is the array that i pass into the print r as the first parameter i like to wrap that in an array and i like to give it an english or in in my case english because that's my language but a human readable title so it's easy to find the content i'm looking at so what i will do typically is i will say uh response object for this one so i just give it a description of whatever this data is that i'm passing it um uh one sec folks and then um for this one i'm going to wrap this in and i'm going to say uh response object methods and then i will get the class methods which returns an array um this is all just stuff that i've used over the years which is why i could remember it uh so i'm going to pop that in there and that will give me what i need alright so let's make this request again and let's see what happens so i make the request again there was an error so i've done something wrong somewhere which is fine um let's go and have a look at the log see if we go into the logs directory there's nothing there so i've done something wrong in here um it might be what i've done yeah so let me try this one take that one out see if that one works there we go okay so the second one failed uh that's fine we'll have a look at that in a second so let's have a look at that first log um oh it's not oh dear it's not logging to the right place i have configured something incorrectly oh wrong site this was copied from my other test site that i used so this site is learn press so let's do that so it's the learn press site let me try that again um now we should get a log file there we go there's my debug log there is my response object you see that's how i give it a i give it a nice heading so it's clear what i'm what i'm going to be working with here is all this data that we saw earlier um if you remember we saw this all on screen here is the response object data status response um i just want to see if the methods are in here i don't think they are uh so i want to get them from the from the object okay so that was that um let me see what's wrong with this one i was pretty sure class methods was a an array um oh hang on wait let me let me do this let me do this maybe it's not an object that could be why maybe i can't get maybe i can't get a class methods on the object that might be why um so let's see i've never done this before so trying things live here always fun hey okay let's see what that does see if that gives me an error yeah but that's probably the problem so now let's see what we get in the debug log we should get some kind of error about that here we go get class methods here we go must be an object or a valid class name so it's not it's not returning it as an object so i can't get the class methods on that okay so let me so that means that very possibly this code as elliot's pointed out doesn't work so let's test that so let's do this and then let's say error log let's just get the message sorry folks pressing the wrong buttons here let's just get the message return that is true and then i'm just going to wipe my debug log for now and i'm going to comment out this one because i want to see what happens if i try and get that error message there we go and let's do that oh wait wait wait wait yeah so it looks like that get error message is isn't correct um i must have copied that copy that response somewhere incorrectly so i apologize for that elliot's point was correct it doesn't look like there's a get error message um it must be a hang on let me just have a look here let's check the documentation so let's go to where are we now i can find my wait let's go get error message oh it's wp get error message single error message what i'm looking for is okay so now i'm going to do something that i don't often do i'm going to start diving into the wp remote get function call and this is inside the http class and i'm going to search for get error message here no there's no get error message there so let's go into that that's the object there that's what i want that's what i want okay now there is no get error maybe it's get error no alright let's see if the documentation for wp remote get tells us how to check that error um that's the response code that's specific header basic authentication it's nothing about checking an error so let's check remote get um it'll return a response or error on failure tree body retrieve response code it looks like yeah it looks like that get error method that i was using doesn't actually exist on the response um would only work illiot says belongs on the wp error class would only work if remote get was an error so yes good points on that one um so let's go back and fix that so illiot was saying um this would only work if it was an error so you wouldn't use it that's where i went wrong it would be up here i used it in the wrong place thank you for pointing that out illiot um so the error message i would get if there was an error and then i would be able to get the error thank you illiot for pointing that out i was using it in the wrong place apologies folks that's how that would work okay but the point that i was trying to make there um was if you can if you can set up some way to debug your responses and debug your errors and look at them in logs it is a handy way to to find out what's going on and then you can start diving into the code into the documentation of those things awesome thank you thank you to illiot for pointing that out i'm just going to quickly scroll back through the um through the notes to see if there's anything that i need to check illiot says logging by date is useful to isolate pinpoint reports areas yes scraping logs to be painful when trying to find specific dates um i was watching how this troubleshoot is actually quite educational i just panic when i get errors i do too you can't see me panicking but i am um and then illiot pointed out about it belonging to the error class that will 100 correct i had it in the wrong place thank you illiot i will update my notes about that i don't know where i copied that from okay so that is how a request might work um sending a a request to fetch data is very very similar uh so let's have a look at the documentation on that one if we go back here we can go to the posting data to an external service um and essentially it's the um WP remote post function so i'm going to paste that into the chat i see Sergio says for W for debugging i often use WP shell yes i love WP shell from WPC Li um it's one of my favorites uh Felipe points out the documentation um is clarifying about what's returned exactly correct so thank you for sharing that there so with a post you are making a request again to a URL and if we have a look at our documentation for fake store um if we want to add a new product we will see it as a post method um and then it requires a body a body of information in this case it's again it's a json body and so we would pass in a title a price a description and all of those kind of things so to make a post request is a simple case of changing the function and changing the data being sent um so in my example here i'm going to simply set that up and then we can post that data so let's take our that and i'll show you what something like this might look like so here you would go WP remote post it happens to be in this case it happens to be the same URL and this is often the case with web is the same URL is used to make the fetch and to send the data the only difference is the verb or the request method that is being used is change from a get to a post and in WordPress because you're using the built-in get or post function that verb is set up by default as Felipe pointed out there is also the WP remote request function which essentially remote get and remote post are wrappers for the request function and the request function sets up the header sorry the verb be it get, post or whatever the case may be so to make a post request you use WP remote post the other thing you often will need to do is you will need to send some kind of data so you would need to set up some kind of data array usually in this case according to the documentation what i'm seeing here let's go back to fake store is it is a JSON object that you need to send and it's title products etc etc etc now what's cool about the WordPress HTTP request API is that you don't have to take the array and convert it into JSON the request API will do that for you so all i have to do here is i have to set up an array inside of the array i set up the body item which is the body that i'm sending to the endpoint i create a new array and then i can simply just start passing in my fields so i can say title and i can say my new product and then i can say price let's say let's go over here say price it won't be my new product it will be whatever the price is and so on and so forth i'm not doing my arrays correctly here so let's make that do that properly there and then let's do not that one no that one thank you it's not getting used to my keyboard if you can believe it and so usually you would send have i done something there we go usually you would send this as an array with body and then the array updates are there and then you would pass this as arguments to the request so usually you would set up this array you could call args or arguments whatever the case may be and then you would pass these arguments into your post to then be able to create your data you can use similar checks so you can check if the response was an error or not you can check whether the status code was correct or not in this case it says if an error happens in this case it says because this is a test API it says if you set an object like the code above it will return you an object with a new ID nothing real will be inserted into database if you want to access the new ID you will get a 404 error so all we should get back is an ID value from that response so we should be able to do the same kind of 200 code we should be able to do the same kind of body get remote body and the same now this time we won't necessarily get product data we will probably just get some kind of data back so what I'm going to do here is I'm going to pop that into there I'm going to just clean that up quickly and then I'm just going to print r of the data just because I'm expecting it to be an ID and we'll say true actually we don't need true there because it's inside of the PRE tags okay so there we are setting up our post request we're setting up our body we're setting up our data to send in the body as arguments to the request okay now we're getting critical errors because I've done something wrong so let's see what was logged in the debug log and it says object of standard class could not be converted into string on line 67 so let's have a look at that and see what that's telling me so oh because I'm doing print not print r sorry folks there we go print r I don't know why print came I don't think I've ever used print in PHP land so let's see there we go so there's my standard object so it returns the ID it happens to return the title and the price as well so I could then use that to check if I get the ID yes it was added and if I go and that is often as simple as it can be to send data to an API we'll dive into just now into some of the more advanced things that you can do but really if you can master the get request and the post request you can do most things with external APIs okay I see Felipe's posted a comment sometimes the response might come with a 200 status code but an error message might come inside the JSON data return it depends on the API personally speaking handling all the possible failures coming from an HTTP request is always the most challenging for me that's a very good point and one that I wanted to mention so now's a good time to talk about so first of all I'm going to say this and I've seen this is not necessarily my opinion but I've seen this in other spaces I've seen people talk about this in other spaces I've done this by accident so I'm happy to admit it but sometimes when you're developing an API when you're developing an HTTP API so a way for folks to connect to your service and retrieve your data you might be using some kind of boilerplate service or some kind of scaffolded code and you scaffold your get request for example and so the framework that you're using or the tools that you're using only expect you to set a different response code if there's an error and so when you're writing your code you forget to do that you forget to set the response code for an error and the default response code if you don't specify one is 200 so what happens is folks make requests an error happens the developer sets the error but doesn't set the correct response code so what you end up with is a 200 response code meaning everything's okay but everything's actually not okay so it's a good idea as Philippe points it out to get the 200 check and I'm not doing this today because I didn't want to dive into that too much but to get the 200 check but also check if there's some kind of message so if we have a look at the WP remote to tree functions in WordPress land sorry to bother you Elliot has a question he's saying not sure if it's relevant for the workshop but his question is are there any considerations for rate limits in the context for external requests okay I'll get to that when I'm done yeah thanks for pointing that out so if we have a look at there's response code WP remote retrieve response message so that is the method sorry the function that you would call on the response object to get if you remember let me see if I've got that data still in the debug log somewhere no I don't have one right now but if you remember I showed you in that array there was the response code and then the message below that the response code was 200 the message was okay it's a good idea to check both let me go back to the code to check both the code and the message because the message might include additional information so you could do something like this you could say message equals WP remote retrieve where is it now there we go and then you would pass again you would pass the response into that and then check the message and maybe what I what I've actually done in the past and I did this with the Seriously simple broadcasting plugin that I showed you earlier every time a request is made I log the response I log the request the response and I think the message because sometimes when it goes well but there's a problem then the message is useful information so yes be aware that sometimes APIs do have that problem if you're working with an API the returns are 200 code but there's actually an error report that to the developers because I can almost guarantee you that's a bug on their side they really should be forcing the response code correctly and I know this because when we picked this up on our API I spent I think a day and a half going through every single request that we had that didn't have a explicit response code and if it was an error response I was adding those response codes and I learned a lot about response codes that day it was years and years ago so yes sometimes it can happen and it's not right so be aware of being able to do that as well okay it is not sure if it's relevant to this workshop but are there any considerations for rate limits in the context for external requests that's a good question and that actually goes into the next section of this workshop so I'm glad you brought it up if you have a look let's go back to the documentation the very next item is called performance in the documentation so let me share that with you and in that section on performance the developer documentation talks about not only when your application has to make a request your application has to wait for the server to respond but also there might be rate limits on the API that you're using for those of you who don't know what a rate limit is sometimes it'll have like you can only make a request a hundred times in a minute or whatever the case may be so that's why it's a good idea to cash your responses especially if it's something that you're not going to need every time you make the request you're not going to need the most up-to-date version of that data it is unfortunately outside of the scope of this workshop but I am planning on doing a workshop on using the transient API or the transient API if you speak with an American accent and this is a way that you can cash I see AJ laughing at me now I see this is a way in WordPress that you can cash that data so you can let's say you're connecting to an external service to load products for some kind of service that you're running that's connecting to maybe Amazon or something those products are not going to change a lot so maybe you cash that request once every hour whatever the case may be and you can use the transient API to do that so that is something to consider thank you for pointing that out we will do a session on the transient API and figuring out how that works but unfortunately we don't have time for that today okay are there any other questions before we move on there's a couple of advanced things I want to show you I always find the downsides of these workshops is I can't show you everything I can't show you every use case everything to think about it's really just introduction to these things but hopefully this starts giving you an idea of how these things can work so that if you need to make these requests you know where to start looking alright the last thing I want to cover today is a couple of topics so the first thing that I want to mention is that you can make requests with using different methods so if you need to make a delete request and the API requires you to post with a delete method you can use the args array pass in the method as delete and then you use that WP remote request function that I think was for LiPay shared earlier WordPress doesn't have a built in WP remote delete one you can use WP remote patch or update so then you would specify the method that way and you would do it that way generally your get and your post are enough some APIs will allow you to update using post as long as you pass the id in some will require you to use specifically a put or a patch a verbal method so then you can specify those by using WP remote request and then specifying the method in that args array you also have a hope if you have any questions for the previous topic any person doing asynchronous API calls or when doing dozens at a time I'll come back to that once we've covered this there are also additional options in the arguments parameter that you can set if you go to the WP HDP request method documentation you can see all those things there what I tend to prefer to do though is I go into the actual WP HDP class file in my local WordPress install and then all the constants that you can set all there and all the different options and you'll see in this here's the request method and then here are the defaults so I can set the method I can set timeouts in other words how long does it take before it times out and stops the request you can do things like redirection HTTP version all kinds of other fun things but if you need to specify any of those over and above the defaults then you can specify them there you can also specify and receive headers sometimes and here we talk about rate limiting so often this gets back to Elliot's question often APIs will send you in the header the x-rate limit limit the number of requests allowed in the time period and the number of available remaining requests so you can use that to check if there are any x-rate limits or not you can use the WP remote head function to get those header values and then be able to read those values from the response and see how things are working there so you'll see there's an example at the bottom here so in this one the headers the x-rate limit remaining on this one is 4982 and so if I do a few more I've probably got some more time to continue along there that's everything under performance let's look at Sergio's request any thoughts on doing asynchronous API calls for when doing dozens at a time okay so that's a whole separate topic I have built projects that do asynchronous API calls I have generally set them up using something similar to the WooCommerce action scheduler that's what I used at the time it's basically like a bigger version of CRON if you will WP CRON it's a way that you can schedule tasks to run in the background that's how I've done asynchronous calls I know in PHP there is something called I think it's React PHP or something that allows you to do asynchronous calls I've never used that before but yes it's definitely something that is possible in PHP the other option is you can do it in JavaScript JavaScript allows asynchronous calls so you can do that one so there are definitely options out there you kind of need to find the one that suits your project and what you need Sergio says here's a plug one here's a find one WP remote get remote head WordPress, orcs, plugin, faker, press headers get last modified cool is that it will get you the last modified date of that plugin that's what I think it looks like awesome cool and that's the cool thing about HTTP you can make a WP remote get request to any URL it doesn't have to be an API, it could be a website let me show you that, this is fun I think this is brilliant so I'm going to show you that so let's go back into the plugin if you've never seen this before do this I'm going to WP remote get and I'm going to get my home page with my blog just for fun so we're going to go to jonathanbossinger.com and we're not going to pass in any arguments and then let's get the headers as well, why not so let's go let's get the headers I think WP remote head let me just see here so I think I just need to pass in the URL let's do that so WP remote head let's do that and let's do that and I'm going to just assume everything works and I'm going to just log that to the debug log file I hope nobody finds this boring but I haven't done this in a while so why not error log response so I need to print R and you can do this on your own sites if you want to it's a huge amount of fun I think okay let's do that and let's zoom has decided to bother me on screen again so let's move it out of the way and let's do the request and then let's see what is sitting in the debug in fact let me clear out the debug log and then let's check and there we go there are the headers for my website it is running on nginx that is correct today's date content type it's html I expect it to be html it has something called strict transport security set it accepts encoding and cookies it's hosted at pressable that is correct it has the x-clacks overhead canoe terry pratchett header if you're a terry pratchett fan you probably know what that's about it has some links to my JSON and various other things and I can use that to get the data you can make requests to websites like that a lot of scraper tools use html requests in this way to scrape data obviously you'd have to deal with rate limiting I'm not recommending that you do scraping but that is what these tools use so you can build all kinds of interesting and fun things if you know how to request that data all right that's kind of my bit for today I just wanted to share one or two other things with you the one is postman.com I have mentioned this in previous workshops if you are working with apis postman is a great way to test them to test your api requests when I was I'm going to open up postman on my machine very quickly and share postman in the link in the chat you will see when I was testing faker store the first thing I did was I loaded up in postman and I ran some requests because I wanted to make sure that it worked make sure that it got me responses so it's a great way to test your apis before you start writing your code and making sure things work and I do recommend using it as a tool Elliot says postman is essential for apis absolutely there are other tools out there there are a couple of other open source tools I do mention them in the WP rest api tutorials I can't remember the more fan now but my personal preference is postman I just find it to be very easy to use Elliot says I thought I was a three to four I now realize I'm a three I was a three I'm now a 3.5 I've always learned something new watching others don't thank me because some of the stuff came from other folks so thank you Sergio Felipe and other folks who have been sharing links I love receiving information from folks so if you're ever in one of my workshops we have these kind of links please do share them because that's how we all learn together these online workshops are meant to be learned together sessions we used to call them social learning spaces because the idea was that they were not meant to be single presenter presentation they were meant to be learning together presentations so please feel free to bring these links to these workshops I definitely enjoy learning from you all and so we all learn together and we all make each other better alright Sergio says insomnia is open source yes I've had a few sorry I misunderstood you there I thought you meant open source means you're up late at night investigating things insomnia API tool let's find that there we go insomnia risk collaborative API development platform so that's another one that folks can check out thank you for sharing that but I think there's more truth about open source it's something that keeps you awake at night as well so there we go awesome folks thank you so much that was fun I loved diving into all of that as I say it is a very broad topic we can't cover everything there's so much more that you can go into but hopefully it was interesting and hopefully it's kind of show you how these things work in WordPress land if you ever need to interact with or integrate an external API now at least you know where to get started I thank you all for your time I thank you all for joining me today and sharing your knowledge with me I hope you have a wonderful Thursday and a wonderful rest of your week and weekend and I'll see you next week bye bye


at Big Data SV 2014 is brought to you by headline sponsors, WAN Disco. We make Hadoop invincible and Actian, accelerating Big Data 2.0. Okay, welcome back to Big Data SV. This is Big Data Silicon Valley. This is theCUBE, our flagship program. We go out to the events, extract the signal from the noise. I'm John Furrier, the founder of Silicon Angle. I'm joined by co-host for this segment, Jeff Kelly, chief analyst at wikibond.org. In Big Data, putting out some great reports. And our next guest is Bob Wilkinson, COO of Infinity DB. Welcome to theCUBE. Thanks. You guys had a name change recently and some funding. Let's talk about the company update and share with the folks the news of what's happening, name change and funding. We'll get right into it. Sure, so this was really a continuation of some significant moves we made starting in fourth quarter of last year where we announced a broader open source strategy. We announced some native Hadoop integration. And this name change and this funding round is really about taking that to the next level. So we've consolidated our brand assets around the product name, which is now our company name as well, Infinity DB. You know, we're just, we didn't want to split that traffic between the website, social media and whatnot. You know, MongoDB had a similar situation. They were called 10 Gen, they called MongoDB. Makes sense. I mean, you want to brand what you're working on. It's just really easy to have those meetings and customers understand kind of the positioning of it. Makes sense. Let's talk about the funding. How many employees you guys have and what's on your agenda for this year for growth? Absolutely. So we're right around 25 employees now. And this funding is really about largely billing out sales and marketing. The, you know, we, Infinity DB has been in the market since 2010, but not really that widely known until now. We really feel like the product's ready. It's, it's ready to really make some, some waves and make an impact, especially in the sequel on Hadoop Space. And this funding is about taking that marketing and sales to a, to another level. So talk about the marketplace right now. The trends right now are obviously big data still rocking and rolling. You're seeing a lot more money being tossed around just yesterday on the queue. We were talking to folks like, hey, we're here and people talking about budget allocation. Still massive growth opportunity. You guys have a good product and good story. Talk about the dynamics that you guys are addressing. Absolutely. So I think one of the key trends we see, we've been saying sequel is sexy again. But, but, you know, what we see is that there was, there was a lot of momentum and, and noise in the market around this unstructured data.  They, they made a lot of, a lot of noise there. And there's, there's a place for that. But we think there's a big place for sequel. You know, there is, there is just legions of developers that know how to use sequel. At the end of the day, a lot of the data that people want to do, analytics and big data is structured. And so sequel is the right tool to do that. And what we can do with the technology like ours is make that accessible. So make any sequel developer a big data developer. And we just don't think, you know, many, many companies or technologies can say that. And I think another trend that we see that is really important to us is a trend around performance. Performance matters. You know, I think there's, there's been, you know, as Hadoop has evolved and started to gain traction, people tolerated this, you know, batch mode and waiting for things for a really long time. But increasingly that performance matters. You know, that, that ability to get more of a real-time or conversational access to the data matters to businesses. And they're using that to drive competitive advantage for their, their businesses. What do you say to the folks out there that say, oh, the sequel guides, they're just not ready for, it's not ready for prime time. Startups have tried sequel on Hadoop, sequel unstructured. It seems like the, that energy is like pent up ready to explode because, you know, there's an educational issue, right? So, so talk about that, that critique of, hey, you know, sequel's been around. Can they, can they cross over and be the ninja unstructured, you know, agile insight acquisition kind of technology? Talk about that dynamic. Yeah, I think, frankly, I think they need to come back and take another look now. I think, you know, if you looked at the early technologies that were on Hadoop, you know, the many of the open source ones, I think you can see why people said that. And frankly, to this day, you know, you can still see that. If somebody tries to do Hive, they're just likely not gonna have a real good experience. But I think, you know, frankly, you know, Kledera was early with their Impala move and that product has been moving along. And, you know, now you have products like ours come into the space that really take that, take things to a new level. So because it's a product that, you know, it's a fourth or fifth generation product, it's mature, it's been in the space and now it's just bringing it into the Hadoop ecosystem as opposed to many of these other newer kind of open source entrants that are much more, you know, much less robust and much more immature. So I can see why people have that feeling. I think they really need to look at what's going on in the market now. And we have a sense too that it's just really getting ready to take off. So I wanna switch gears just a little bit. So, InfinityB, MPP, Columner, Database, Analytics Database, so you're competing with the likes of Vertica and Green Plum and things like that. But, you know, we've obviously seen, you know, the big data world, Hadoop and NoSQL, a lot of open source technology. But in that world, MPP, Database world, not so much, mostly proprietary software. Why the move to open source? Why did you guys make that decision and how do you think that plays in the larger big data landscape? So for us, it was really a two-prong move. One reason is that we felt like the market needed an open source technology, frankly, in the Columner MPP space. You know, there are a number of Columner MPP solutions like you mentioned, but there's really almost no open source options if you needed that kind of technology. So we felt like that was one. We also felt like this move to Sequel on Hadoop. You know, we felt, we saw this market momentum around Hadoop and then now Sequel on Hadoop. And we felt like that to really participate in that market in the way that that market expects, we needed to have an open source strategy as well. So that's, and it's been good for us. We've seen a lot of interest that we weren't getting before. People are out there looking for open source solutions and there just really weren't that many to find in this space. You know, I think the MONA2B seems to be one that came up some, but it's not really a very, you know, production-ready solution for many people. So let's dig into that a little bit. So from the perspective of the user, are you seeing people coming to Infinity B who want to actually tinker with the code or is it because it's open, it's easier to potentially integrate with some of these other products? What really is the advantage of the open source nature of an MPP database? So what I see and what I hear from customers is that it is really more about the business model and that people can wrap their heads around an open source business model. They understand it's a scaling model that they understand because many of these businesses are faced with hockey stick kind of trends on their data. And when you map that up with many of these, you know, proprietary solutions or appliance-based solutions, the math just doesn't work. But with an open source business model, they understand it. You know, it's much like they understand the commodity hardware model. It's, you know, okay, I know I may need to add servers and then I know I'm going to have to add, you know, some percentage of that maybe for my support services around a database or whatnot. But I think that's by far the number one thing we see. I think, you know, the development community is certainly something we'd like to see over time, but I think that's a secondary objective and a secondary priority from what we see in the market. Well, I think it's a good point about the appliance model specifically. When you've got these expensive boxes, you're talking, you know, really high performance and it's very effective solutions, but they're quite expensive and they don't really fit into that paradigm of the scale out commodity hardware approach that you see in Hadoop and some of the other open source big data frameworks. Exactly. So tell us a little bit more about, you know, customer attraction. What are you seeing in terms of, you know, some innovative use cases? What are you seeing out there in terms of people actually making this stuff work? Because we, you know, we've been covering this market here on theCUBE for years and of course a lot of the talk initially was around the tech. Yeah. But, excuse me, we'd love to talk about, you know, what are people really doing out there in the field that's driving business value? Sure. So I'd highlight a couple of use cases I think. So for products like ours, the best fit is for somebody that's got time series data and they've got this massive growth trend in the data. So they've got a lot of data now.  And so one good example is in the gaming space and more and more now these games, these AZs, especially mobile games are throwing off event streams. So essentially, you know, time series data that's logging everything that players are doing in the games. You know, when I start a race, when I win a race, when I buy something. All those things are events that are streamed off these games. And so literally, you know, you take up one of the more known players. They've got hundreds of millions of events per day that they'd like to do analytics on. And this is one of those, you know, this is one of those problem sets where you take a traditional solution and it doesn't really fit. But what they've been able to do with a product like ours is they've been able to take that data in. They've scaled out to 25 nodes now. So it's a pretty large system. And that's serving up analytics for a couple hundred analysts. You know, so every day, you've got more than a hundred analysts that are running ad hoc queries and whatnot against this dataset. And that's really focused, you know, for them, it's focused around player engagement and ultimately marketing and more dollars for them. I think another use case we see is in and around the telco and the networking space. So again, driven by, you know, mobile handsets seem to be this kind of mega trend that are driving everything from advertising to telco to gaming and whatnot.  And so there's a number of customers in that space that are driving, again, driving analytics value off that data and helping them, you know, ultimately helping people in the telco space serve their customers better. You know, you'll hear the term customer experience management in that space. But ultimately, this is the technological underpinning of that, being able to do that at scale. Bob, I wanna ask you about, as we get wrapped up on time here, the competition, the marketplace. We've been following a lot of the sequel and Hadoop players and, you know, we're very bullish on a week. Agree with you that we think it's gonna explode. We heard Microsoft talking about HD insights with Board and Works. Huge educational opportunity, too, as well. You mentioned some of, you see the movement coming as well. What do you think the critical success factors are for being successful in the sequel Hadoop space? It really is kind of a cross in the chasm when we were kind of joking earlier. But there is mainstream adoption. Sequel, folks know Sequel. There's value there. There's institutional knowledge into Sequel. Yet the opportunities to get insights is what everyone wants. So talk about what people need to do to be successful, both as competition, your company, and also customers. I think the first thing is they need to make it accessible and easy to use. You know, it needs to be something that people can quickly, you know, get in place, get some data in there, and get going with it. You know, I think there's, you know, just with the, there's this cacophony of different technologies out there. There's so many out there that I don't think any, I don't see a lot of, you know, willingness for any one person to spend a lot of time trying to make some of the work because they know they can just go to the next one. So I would say that, you know, the first one is to have, you know, have a product that's simple, that goes in easily and somebody can start to derive value out of quickly. And then I would say, you know, I'm gonna come back to the performance thing again and say that I think the next thing I think is that people really are increasingly looking for that performance. So it's about having products that have the right performance characteristics in the right types of use cases. And then, you know, lastly, I think would be to have the right focus. So, you know, certainly there's the clear trend in the industry in general is to use the right technology in the right space. So, you know, don't try to use an analytic base in a transactional workload. So I think the last thing would be focus on the use cases that you really know and that you're good at. My final question for you is more like on the customer side, traction. Obviously you've got some funding. They do some due diligence. We know how it is. They're gonna go talk to customers. It can be painful, sometimes easy, depending on the space. But talk about the itch that your customers are scratching that you guys are solving. Talk about where you've been successful. What do you guys hit as the key value proposition for your customers and why have you been successful? Yeah, so the common thread between our customers is again when they have this, what's an intractable problem really. I mean they have data growth that's outstripping either their technologies both from a technical perspective and an economic perspective. And so they've got this intractable problem and we can give them an answer to that in many cases. So these people like the gaming company I mentioned like some of the Toko focused companies that I mentioned, they're able to build solutions that were never possible before. And they can do it in a way that's commercially viable and financially viable. So that's what's exciting to us. Final comment I'll give you before we end is what tell the folks out there the state of the sequel over the unstructured database market? What is the big bumper sticker this year for that market? What can you share to clear up any misconceptions or talk about the trends? Well I think the clear trends is that I think it's real, the technology is real now. You've had significant maturity and impolite frankly, which is a competitor of ours, but in all honesty they've come some way.  So I'd say that the space is really maturing and it's maturing rapidly. And you've also got Pivotal in there with Hawke as well. So you've got a lot of players, I think you've got a lot more solutions that are credible and ready to go into production. And so I think I'd say come try them out, try us out and see how our claims stack up against theirs. Congratulations on the funding, the name changed the branding, and it's a growth market. We were just commenting on that at the beginning of the segment valuations are high and opportunities are their value to be had and customers are paying now. So the rising tide floats all boats from Impala to around the industry. So congratulations. This is theCUBE, we'll be right back with our next guest after this short break. We're live in Silicon Valley for Big Data SV covering all the action in Big Data as well as the Stratoconference going on right behind us across the street. We'll be right back.