APIs for Beginners – How to use an API (Full Course / Tutorial)

– Hello, I’m Craig, and I’m a developer. In this course we’regonna be exploring a term that you’ve probably heard quite a bit. That term is API, or Application Programming Interface. In addition to being able torecite what it stands for, when you complete this course, you’ll be able todiscuss what an API does, you’ll understand why they exist, and you’ll be able to list the many benefits that they provide. You’ll even get some hands on experience using a few popular web API’s which will give you a taste of what all this excitement is about. We’ll be starting from the very beginning so there really isn’t too much I’m gonna be expecting you to know before starting this course.I would like to request that you have a touch ofexperience with coding, and a wee bit of knowledge about the web. If you’ve written any program at all, even the typical first program, you know the one where youwrite the words hello world? If you’ve done that inany programming language, you’ll be pretty muchready for this course. It will be helpful for youto have a basic understanding of how the web works withweb servers, and browsers, but don’t sweat it. We’ll touch on this too. Now, if you haven’t yetmet these requirements, please check the notesattached to this video for where to get startedwith some beginning web, and programming concepts. Oh, that reminds me, you should probably take some time to get used to your learning environment.The notes that I just discussedare attached to this video. I’ll also drop moreinformation in that section to keep you updated onwhat might’ve changed from the time I recorded this. Now I’ll do my best toremind you to look in there when there’s something thatI think you just have to see, but you really should get in the habit of checking that area out. There’ll be tons ofjuicy information there.Now these videos have captions, so if you feel like you mightbenefit from having those on, please use them. This space is all yours. If you want me to speak slower, use the speed controls to slow me down, and if you know, I’mtaking too long of a time, just speed me up! I make a pretty good chipmunk, and last, but certainly not least, take advantage of the fact that you are in a video based course. If you need me to repeat myself, use the video controls to rewind me. If you feel like you need abreak to let something sink in, by all means, please pause me. I’ll be right here waiting for you. I know that I’ve gotten intosome bad video viewing habits with all the streaming media. Now, while binging mightbe a great way to consume an entire season of your favorite show, it’s not the best wayto learn something new.Education isn’t meant to be binged, and because of this I’ll probably remind youquite a bit to take breaks, and encourage you to let whatyou just learned marinate. Alright, let’s get to it. API, those three little letters generate quite the buzz, don’t they? Now, first, I’d like totake some time upfront here to clearly break down what is meant by Application Programming Interface. By understanding its purpose,and a touch of its history, I think you’ll startto see its importance, and begin to understand why this term keepspopping up in your life.After we get a good grasp on the what, and the why of API’s, we’ll go, and learn how toexplore to existing ones. We’ll get familiar witha handy tool, Postman, which provides a nice way tointeract with web-based APIs. We’ll use that tool tohit an external web API to send actual text messages, and get some interesting data back from a streaming music service API. After some practice using the APIs, we’ll insert them into a web application. The application we’re going to be building is a web app called Complimenter. Our app will allow you to send compliments to your friends, your families, and your colleagues over text message, and then it encouragesthem to visit your site, and do the same. Now I’ve included the final applications in both JavaScript, and Python, and together we’ll walk throughhow to use external web APIs to solve the missing pieces. We’re going to be strictlyusing APIs in this course. We won’t be writing our own now. Well now you most likelywill end up learning some best practices in API design, we won’t be covering that specifically.There are many great courses available that show the creation thought process, and I’ve linked to some of my faves in the notes attached to this video. In my opinion, the best way to startlearning about any acronym is to focus on each individual letter. For API, I think we shouldstart on the last character, the I, interface. Let’s talk a bit about interfacesthat you’ve seen already. Interfaces are all around us. For instance, this radio here, it has a familiar interface. The interface allows me to dothings like change the volume, change the station, I can turn it off, and on. I literally have no idea how anything inside this thing works, but still the interfaceallows me to control the way it works through theoptions that are exposed.The magic that is happening is completely abstracted away from me, and I’m still in control of what has been determined,that I, a user, can handle. Interfaces usually evolve over time, like an alarm clock radio for example. It has my familiar volume,and station controls, and it also adds some newfeatures like changing the time, and setting the alarm. I still have no idea how thisworks implementation-wise, but the interface is something that I can understand usually, and as technology evolves, and new options come into existence, they make their way into thenew versions of the interface.Still abstracting away things for us, but enabling us to be incontrol of the new features. Sometimes these physicalinterfaces get so recognizable that they even make their way into GUIs. Did you hear that? There it is again, gooey, orGUI, Graphical User Interface. This is my streamingmusic app on my phone, and there’s my familiar play button in the User Interface, or UI, and I know what that playbutton does when I press it, but I have no idea how it does it, and I’m okay with thatlevel of abstraction. I depend on it even. What would I do in publictransit without music? Like talk to people? Hi, how’s it going? Now the developer who wrotethis streaming music application of course understands howthe play button works.She coded the button sothat when it gets clicked, the music starts playing. Here’s the thing though. Our developer is also working with quite a few interfacesthat are abstracting away some of the details for her. For instance, she wrote code that happens when the button is clicked. She probably did that using anEvent Handler on the button.What she didn’t have to do however, was write the code thatmakes the button interact, and change with the press. She didn’t have to write the code that makes that familiar clicking noise. It was already there for her. Buttons are in fact an interface. They provide the developer the means of controlling its interactions while abstracting away how that actually works,implementation-wise. This button is part of the API, or Application Programming Interface, that’s available fromthe application framework that was used to create the app. Because most apps need buttons, this interface has beencreated to help our developer, or application programmer to use. Now by implementing the button interface, our developer was ableto make her code run when the button was clicked.It’s worth noting that the code probably also uses a media player API that’s provided by theoperating system of the device like Android, or iOS. This media player API abstractsaway needing to understand the details of how to sendaudio data to the hardware. The developer knows thathe just want to call the play method of the media player API, and I suppose too, the song isn’t stored on the device. It’s being streamed over the network, so a web based API call has been made over theinternet to get the data. It’s actually APIs allthe way down to the ones, and zeros providingabstractions at many levels.Let’s take a look at what all these interfaces have in common. They all define ways for us to interact, or communicate with an object, whether that object bephysical, or software, and as a user of the interface, we don’t need to understandthe implementation. We don’t need to know how it works. We just need to know what we’ve been allowed to change, or see. Interfaces abstractaway the implementation. Now, while the UI, or User Interface is made forthe user of the application, the API is made for theapplication programmer to use, and extend in their applications with the I covered in our API, let’s take a deeper look atthe rest of the API acronym. An API is a contract of sorts, it defines how it’s expected to be used, and it defines what you canexpect to receive by using it. Think of it as a set of tools designed for softwaredevelopers like yourself. An API is created to helpmake your life easier by giving you access todata, and by providing you with an abstraction of the implementation.You know, not needing to know how it’s doing whatever it’s doing. They save you from needing tocreate everything yourself. When designed well, they make doing nearlyimpossible things happen, in just a few lines of code. You’re probably startingto see why it’s important to get familiar with them, right? I want to do a quick word of warning here about some naming issues thatyou’ll probably run into.These days, The term APIis almost always used as a way to explain web-based APIs. In fact, it’s probably safe to assume that when you hear API in the wild, it’s most likely thatpeople are talking about a web based API. Now we’ll explore those here in a few. However, if we focus on all types of APIs instead of just the web based subset, we’ll get a better look into why web-based is are so popular, so hang tight, we’re getting there. APIs are everywhere inyour software journey, just about everywhere you look. Your programming language, whichever one it mightbe provides many APIs. Let’s take a look at onethat’s common in all of them. They all provide some wayof working with strings, you know, like a series of characters. You want to make your textile upper case? Just call the API method, and voila, you could probably createthat uppercase string all by yourself by doing some sort of low level bit math on each character, but you don’t need to, because your programming language has abstracted that away for you, and provided a handy string API.It exists because this isa common enough problem that developers run into, because these programminglanguage specifications are just interfaces, different operating systems can supply their own implementations so that the code worksproperly in their environment. I think an easy way ofpicturing this is to think about how different operatingsystems like Windows, or Mac OS maintain their files. They’re totally different, yet your programming language provides a single API forworking with the file system. You can write one script, and it works in either Mac, or Windows. It’s the implementation that takes care of allthe details for you. Pretty cool, right? Definitely something to be thankful for. It makes our life so mucheasier not having to worry about what operating system is being used.The importance of an API to a language cannot be understated. There’s been some fascinating legal cases where it’s been questionedif the language API itself, again, not the implementationcan be copyrighted. Check out the notes for more on that. Along similar lines, thereare different web browsers, you know like GoogleChrome, Microsoft Edge, Safari, Firefox, and Brave. Now you might not havepondered this before, but isn’t it amazing that youcan write code for the web, and it will work in any of them? Now this works becausethere’s a set of web APIs that web browsers all must implement in order to make thatmagic happen for you. We’re standing on theshoulders of giants folks. We really should thankthose giants more often. There are authors, and maintainers of librariesthat package up code, and solve common problems so that you don’t need to do it yourself. Like for instance, do you know how to programmatically make a photo black and white? Mean neither, but I can downloadan important image package into my application, and suddenly I can.I just call a method, and boom, I wish real life skills worked this way. I’d import dancing so itcould be more fun at weddings, cha cha cha. Frameworks provide an API that allow you to extend what has been providedto make it your own. Like for example, most web frameworks provideyou with the ability to add a new route toyour web application. It allows you to write out dynamic data to a template that you specify, and you do all of this withjust a handful of lines of code. You don’t need to understandhow it’s doing things, but you do need to know howto write an implementation to what the framework is expecting. In this case, you’re using the API, the contract to writea valid implementation that meets the requirements. All of these APIs thatwe just talked about, they’re local to our code base.They exist within our code. We use them to avoid recreating the wheel. That is to say they assistus in accomplishing tasks that we need to perform by abstracting away a ton of work for us. The stuff that we developersshouldn’t be worrying about. We should be focusing on thebusiness problem at hand, and that means a big partof your job is figuring out how to leverage theseAPIs to your advantage. Now I think it’s an excellenttime to take a quick break. I just gave you a lot to think about, and I’d like you to takea minute to breathe.Why don’t you jot down someAPIs that you’ve used today, even if you weren’t coding. I know that you’ve seen some in action. If you’re having a hardtime thinking of some, I’ll give you a hint. You’re watching a video rightnow inside of a web browser. When we return, we’ll explore the concept of remote APIs, ones that aren’t executinglocally in our code base, and why that’s such a powerful concept. (calming electronic music) It took me a while tofind this remote control. It was in the couch. It’s always in the couch. Anywho, this remote hasan interface on it, right? There’s the power button, and there’s a channel changer, and when I press the volume button, it sends my request to my device, and the volume changes asif I turn the volume up using the interface on the device itself, and we know why that’s important. I want to remotely control my device. I don’t want to get up from the couch. There are of course more, or less lazy reasons as to why you might want to remotely control objects.This cute little robot, forinstance, has a remote API. You can send commandsto it, and it responds. It even sends back sensor information. These traffic signs canchange based on an API call. This drone here, it’s actually remote controlledby an app on my phone. See? It’s not just physical objects that benefit from remote APIs. Oftentimes we don’t havespace on our local machines for all the data that’s available. Like for example, have youever used one of those apps that helps you figure outwhat song is planning? You send up a snippet of a song you heard playing at a grocerystore using your microphone, and it sends backexactly what the song is.It’s usually Phil Collins. It turns out both grocery stores, and yours truly, loves Phil Collins. You don’t have room for all the songs inthe world on your phone, and with this remote API, you don’t need to have all of them. It does all the searching, and processing, and it’s surprisingly quick. How can it possibly do that? I don’t know, but I love the interface. It’s so fast. There’s another benefit ofremote APIs, computational power. Because an API removes the limitations of your local machine, you can gain access to seeminglyinfinite amounts of power. A good example of that is theAR app of Google Translate. You can use the camera on your phone, and in near real time,it’s able to translate directly to your screen,like, instantaneously. It’s using a ton of processing power to make this magic happen, and that processing ishappening elsewhere. (speaking foreign language) It took quite a bit of experimentation, and some evolution of ideas, but over time we finally turned this remote API dream into a reality.Now, I’m gonna drop somehistory in the teacher’s notes, but I just want you toknow that the struggle to achieve this concept ofremote APIs was very real, but most of the problem was that there wasn’t a standardthat everyone loved. Things were pretty clunky for awhile as the ideas were sussedout, but then it happened. A new architectural styleappeared that was clear, and allowed us developers to interact with specific resources over the web, and it quite literally changed everything. This style rapidly emerged as a winner, and just about everyone began offering, and consuming APIs over the internet, and what I’m talking about here is REST, or Representational State Transfer. It was the approach that we needed, and honestly it’s the abstraction that we developers deserved. Like we talked about already, the popularity of REST spreads so rapidly. It nearly completelyovertook the term API. It’s like how we use theword Xerox to mean photocopy, even though Xerox is justa brand of photocopier. Xerox does other stuff too, I think. That’s how pervasive REST is.REST is for sure not the endall be all of remote API’s. There are definitely some limitations, which we’ll discuss here in a bit. Technology is ever evolving, and of course there are movementsthat are still advancing the concept of the best remote APIs, some terms you might’veeven heard, like GraphQL. More on this in the teacher’s notes. For the rest of this course, we’re going to be doinga deep dive into APIs that are written using the REST style.When APIs embrace the styleand constraints of REST, they’re said to be RESTful. Cute, right? If you’re feeling like youneed a little rest, go ahead, and pause me before wedo a deeper dive into what it means to be RESTful. Sorry, that was a bad, and obvious joke, and as a developer youkind of have to make it, you don’t really have an option, and because REST sits ontop of web technologies, we should probably doa whirlwind refresher of how the web works.(calming electronic music) It might’ve been a whilesince you thought about how the web works. There are a smattering of terms that I’d like to reloadinto your working memory before we talk moreabout how REST uses them. So let’s use the web. I’ve got my computer here, and on it I have an internet browser. This browser is a web client, and I’m going to use itto connect to a server. I’m going to do this by putting a location in the address bar, a universal resource locator, or URL to be exact. You might also hear this referredto by a superset term URI, or Universal Resource Identifier. Now our URL here has a scheme portion, and this one happens to be HTTP. HTTP stands for HypertextTransfer Protocol. Let’s break that down bit. Let’s grab that last part, protocol. A protocol is also oftenlikened to a contract. It’s a little lower level than an API, but it’s similar in concept. You can think of it asdefining the expectations of how to communicate.An example that I findreally sticks with me is if you’ve ever been to a rally, and someone does one ofthose chants where they go, when I say food, you say bar, food bar, foodbar, here, let’s do one. When I say H-T-T, you say P! H-T-T, H-T-T. I just realized I might’vemade you yell pee out loud. I hope you’re in a coffeeshop, that’d be awkward. Anyways, we, you, and I, we just set up a real quick protocol. I told you how to respondto my specific request, you would have been breakingour agreed upon protocol if you yelled anything else, but P. So the browser createsan HTTP request for you. Along with the URI, it also specifies a particular HTTP verb. In this case, it’s using the GET verb, which is used to clarify that this request will only receive data. That is, it won’t be making any changes. The server receives the request that was transferred from the client. There’s that second T.The server then does thework that it needs to do, and finally it generatesthe resulting webpage, and sends back a response to the client, my browser in this case. Now, the most important partof that response is the body. For a webpage that contains the HTML, or Hypertext Markup Language, which gives us the remaining parts, the HT of our acronym. Hypertext is text thatcan link to other texts. In HTML, we perform thatlinking with anchor tags. So with that response, the browser renders the page. When one of those links are clicked, they kick off a brandnew HTTP GET request, and the process repeatsitself over, and over. In between those clicksthough the protocol is done. We made the request, we got the response. HTTP as it was originallydesigned is a Stateless protocol. Once that request receives a response, it’s all done. If you want to keep some sort of state, your client will haveto manage that itself, and set it up with each new requests. Check the notes for more on this.There are more HTTP verbs, also known as requestmethods, besides GET. Most common scenario you seeis when you encounter a form that is used to take information from you, typically you’ll see the verb post used to explain that you are submitting, or posting data to the server. Okay, so our protocol that’sused to transfer this hypertext is admittedly a little more complex than our rally chant was. There’s quite a bit ofimportant information that’s included in both therequest and the response. You’ve probably seen querystring parameters, and URLs. You know, the stuffafter the question mark? This is one way to passinformation about the request. Another common way this information is passed around is through specific key, and value pairs, called headers.Both requests, and responses have headers, and they’re used tohelp further communicate what is wanted as well aswhat has been sent back. Now, some of the popular request headers allow you to specify information about the content that you’dexpect back like the language, or the type of content. You can also state you only want a page if it has changed since a certain time. This technique allows for caching which is a powerful concept. Why get the whole page if you already have itin your local cache? You can embed authentication information in each request using a header. This way you are essentially keeping your clientlogged in across requests. The response also contains headers. A super important one is the status code. This lets you know whathappened on the server side, and it can convey thingslike missing documents. I’m sure you’ve seen the old 404 error. The page has been moved, or hopefully everything is A, 200 OK. It can also explain the content type, how large the data return is, and many more things. Okay, got it? Feeling good about thatlittle whirlwind tour? Remember, feel free tomake me repeat myself if that was way too much.I totally get it. That was a lot of information. It’s important to have a basic understanding of these things, because REST sits on top of them. It uses the concepts that were introduced with the web to expose resources that can be accessed, and manipulated. Let’s take a look at how the RESTful approach takesadvantage of the web, and it’s tooling foryour benefit, and profit. REST stands forRepresentational State Transfer. APIs that meet the RESTarchitectural style constraints are considered to be RESTful. A typical way to teach about RESTful API’s is to cover the constraintsthat define it all up front.I don’t know about you,but personally I find approaching learning thatway pretty overwhelming, especially from the beginning. I mean we haven’t evenlooked at an API yet, and on top of that, most of the REST APIs that you use will meetall of these constraints. So here’s the thing, I promise that we’ll goover all the constraints, but let’s do it on our own time. Like don’t learn themall, right this instant. We can even make it a fun journey like a RESTful constraint scavenger hunt, complete with prizes. Here are the guidingarchitectural constraints required for an API tobe considered RESTful. We’ll check them off when we discuss them, and then we’ll loop back oncemore at the end, and review.Got to collect them all. Sound fun? Good. Let’s get started talking about how REST APIs sit ontop of web technology, like a little hat. Much like the web, the client makes a request to a server. The client in this case is typically going to be your program, and you’ll probably beusing some sort of library to create the request to the server. The protocol used is, you guessed it, HTTP, and it’s Stateless. The server won’t remember anything about the particular client. If you want to maintain statelike your login details, you must send it witheach, and every request, and you’ll do this using headers, and just like that, we’ve talked about twoof our REST constraints, Client-Server Architecture, and Stateless. You got two knocked off already. You’re on a roll now. We should probably talk about what that request was requesting, right? Well, it most certainly wasrequesting about a resource. A resource is a little abstract, and that’s intentional. It’s the R in the URL, or URI, we use the term resourceto reference an object, which also happens to bepretty abstract, right? This is because we can use resources to describe just aboutanything that we build.For instance, let’s imaginean ebook store website. On the homepage, maybe there’s a list, or a collection of new books. Each of these books is a resource, and we click into thatto take a closer look at the book resource, and we see a link to the author, which is also a resource. We click into the Author Resource, and we see a collectionof all the other books that they’ve written. Maybe we even see a group of fans. Again, another collection, and each of those fans are a resource. Clicking into a fan resource, we can see the collection of their favorite authors, and books.Everything is a resource. Let’s change gears. How about an image sharingapplication on our phone? So we have user resources. Those users post photos, which are resources, and the photos can be loved. So there’s like lover resource. Maybe there’s an albumthat could be created, and there’s an album resource that contains photo resources, and albums have a collectionof contributor resources. Turns out almost everythingwe ever want to build can be expressed in terms ofresources, and collections. Most of what we want our applications to be able to do to theirresources can be expressed through the unfortunate sounding acronymCRUD, and that stands for Creating, Reading, Updating, and Deleting. Now as a user of the ebook site, all we did was a bunch of reading, no pun intended. Actually I did intend that one. We were reading, right? Just getting the information to display like we retrieved the author page. We made a read request for that page. The web browser used a GET request to that specific author page.Now the RESTful APIfollows the same logic. Your program sends a GET request to a URI. Then the survey response with data, and of course all the HTTP headers that you’ve come to know, and love, and the body is typicallyrepresented these days as JSON, or JavaScript Object Notation. Now, JSON provides agreat way to structure, and nest your data. Every programming languagethat I can think of provide some means ofturning a JSON string into a native object. Content type is typicallysomething that you can specify on your request if JSON isn’t your thing. Now, if you recall, there areother HTTP verbs available. These verbs are used in REST APIs to clearly state theintention of your request. Want to add an author? Post to the /authors, and send the data that you want to update in the body of your request.These fields will bedefined for you somewhere. Want to remove an author? Send a delete to that specific author. Updates typically support the patch verb, and you’ll see we’reable to represent CRUD, the Create, Read, Update, andDelete using HTTP methods. Pretty cool, right? What this means is that you can interact with any application out there that’s exposed their REST API.You could grab dataremotely automate tasks, and even smush services together. This is called a mashup,and here’s the thing, there are tons of APIs available just about anything you could imagine, and if they’re truly RESTful, they’ll all feel pretty much the same. You can build anything. There are services that allow you to do incredible thingswith a few simple API calls.So now the question becomes, what are you gonna build? Why don’t you take a quick break, and when you come back, let’s explore a RESTful API together? We’ll take a peek at how to use the music streaming service, Spotify, and they’re excellent RESTful API. (calming electronic music) You have some new found understanding of how web-based APIs work. I’ll walked you quickly throughsome imaginary REST APIs, and now I’m thinking it’s time that we get a little more specific. Why don’t we go exploring together? Now, some of these REST APIsallow you to give it a try from the comfort of yourvery own web browser, and one of my personal favoritesthat allows for exploration is the streaming music service Spotify. So here I am at Spotify.com, and a quick word of warning, this for sure is going to look different. By the time you get here, there are teams of people working on the site to make it better, and you’re gonna have thebenefit of a better website than I have right this instant.So just a reminder, you should check the notesattached to this video for any breaking changes, and if you don’t have a Spotifyaccount yet, don’t sweat it. As you can see, it’s free, and that same user that you can create, you can end up using fordevelopment purposes. So let’s assume that I didn’tknow that Spotify had an API. Now, what I usually do is I look around. So typically most sitesstore the nerdy stuff down here in the footer. There we go. Developers, that’s what we’re looking for. It’s a community of developers. That’s us, let’s do it. Wow, I love a site that treats me well, even as a developer. This is really nice, right? So you can do a ton ofstuff since I was last here, let’s take a look here from the front.So audio analysis, wow, you can learn about danceability, maybe I will be able toinstall that skill after all. Oh, cool, audio playback. So you can kind of nice, you can embed a player right in there. You can put a playerinto your application, an SDK here, that stands forSoftware Development Kit, and we’ll look at oneof those here in a bit, but basically what it doesis it gives you an API that wraps around other APIs, and it will feel native toyour programming language. Cool, and then let’s take alook here at recommendations. Oh, awesome. It will give you specific recommendations. Awesome, this is great. Target danceability, I’mgonna be able to dance, and see this JavaScript here, it’s doing a GET to oneof their end points.Awesome, this looks good. So let’s take a look up at the top here. Let’s go ahead, and discover that’swhat we’re trying to do. We’re trying to discover what we’re going to do with this API. So let’s click into here, and this will give us someideas of what we can do. Let’s see. Real apps that integrateaudio features in. This is awesome. I love when sites do this. I find that it’s a greatway to get inspiration if you don’t yet have an ideaof how you might use the API. You can see how other people have used it.Cool, so this is the audioanalysis that we had seen, a quick dashboard ofaudio features of songs, and there’s that danceability again. Here’s playback, so you can get a player. This is super neat, and these are apps that use them. iPhone app, a listening room, Runkeeper. So you can see here, this is for iOS, and this is for Android based phones. So iOS being like Mac based products, and this is Android based products, and this is widgets. I’m not exactly sure what that is. I’m assuming that’s the HTMLwidgets that we had seen, and that’s cool, right? Because it’s a web based API, all we need to do is toconnect to it over HTTP. So any of these devices can connect to it. Pretty slick. Alright, let’s keep going. So we’ve got recommendations.That’s great. I always need music recommendations. Search, oh, that’s nice. That actually feels like a goodplace to get started, right? And like if we went, and we searched for different things, so there’s six degrees of Kanye West, I guess a lot of peopleare connected to him. Find other artists that arelike the artists you like, this is great.Why don’t you say, we look at some of thedocumentation for search? So I’m going to click this, read the docs. Let’s read the docs. Oh, nice, now you might not see this, but there’s a brand newweb API reference in beta, which means it’s notquite ready for everybody, but it’s ready for people to try. I’m gonna go look at that. You might actually be there, and be out of the beta periodby the time you see this. Okay, so let’s take a look, and let’s see about this Search API. Let’s see, Search API. So let’s go ahead. Let’s click into there. As you use more, and more APIs, you’ll get super familiar with reference documentation like this. This is explaining the contract of what we need to do to use this API.So you’ll see here thatthere’s different parts. So this is what the request is that we’re gonna be sending, and it’s saying herethat this is a header, and this says whether, or not things are required, and this indeed is required. So this is authorization here. There’s a header that’s required in the request for authorization. The authorization means itknows what you’re allowed to do, or authorized to do. Spotify, and many other APSuse the concept access tokens. So then, so that’s a header, that’s the header that’s required, and so here we see thisquery parameter, right? So query parameters, and you’ll see that thisone’s required this queue.So this is the search query, the keywords, right? So, and here’s an example of what that is, and this is showing you thatit needs to be URL encoded. There’s some more noteson this here in the bit. So no, we have queue is required, and also type is required, and type is like album, artist, playlist, like the type of resource that is available in Spotify’s API, and if we keep scrollingdown, there are more, there’s more optional queryparameters that are available. Really help you specify your search, very rich API they have, and then it shows you this response. So this is what’s gonna come back. So you’ll see that you’ll get a header, and the status code, very important. We’ll say 200 okay. If it’s good on success rate.On success I’ll say 200 okay, and the response body contains an array. So like a list of artists,objects, or album, artist, whatever it was the typeyou were looking for, and it’s going to be in JSON format, just like we talked aboutJavaScript Object Notation. And so you’ll see when there’s an error, there’ll be an error code, and the body will have the error message, and then there’s some more notes here, and these are really thorough. This is great. So in code spaces, that’s what we saw. We saw that %20. It’s making sure thatyou can’t use a space, otherwise it breaks the URL. So this is how you do that. You’ll see there’s lots ofdifferent information here. Yeah, you can use asterix, and show you in all sortsof ways to do fun queries. Let’s go ahead, and trythis out in the web console. It’s pretty slick. So what this does is itlets us search for an item, and it’s showing us how it’s doing.It’s doing a GET, and it’s does have someauthentication required. So we will need to build something here, but you’ll see over hereit’s showing what it’s doing. It’s doing a GET to this URL, and this is code herethat will actually run, and you’ll see as wechange the fields here. So I’m gonna change this to a very popular artistaround my house, Lizzo, and you’ll see that it updated over here. It updated my query, and thetype is set to artist already. So that’s fine, and we have this OAuthToken that we need to get. So we need to get this token. So again, this is the, what are they authorized to do? So we’re going to go, and choose Get Token, and it’s telling us thatthis specific endpoint doesn’t require any specific scopes.So these are scopes that you can do. So when you build this token, it’s saying for using this key, these are the things thatthe people are able to do, and we don’t need to doanything specific for this. So let’s just go ahead, and let’s not check any of these. We don’t need to modifya private playlist, we don’t need to do that. So we’re going to do Request Token, and here’s it’s gonna askus to log into Spotify, and if you have Spotify,go ahead, and log in, and if you don’t remember, it’s free, you cantotally just come in here, and do a sign up. And we can put in our emails here. So I’m going to put in mine, and here’s a little trick, if you don’t know this yet, I’m gonna put in API course.Let’s do API course like this@gmail.com. My email address isCraigsDennis@gmail.com, but if you put a little plus here, you can kind of categorizethings your own. So just a little trick, and that way if you’re worriedabout emails coming in, you’ll know that they’recoming in from that address. I’m gonna do the password to my luggage, which is one, two, three,four, five, just kidding. What should we call you? I love it when you call me big papa. Alright, so my date ofbirth is November 19th, and I was born in the wonderfulyear of 2000, just kidding. This is awesome. I love this Spotify. Thank you for being inclusive,inclusivity matters. I’m gonna choose Male. I don’t want to sharemy registration data, and I am not a robot.I promise. I think I’m not a robot. Identify the crosswalks. What is that? Alright, so there’s one that’sdefinitely a cross walk. That’s a crosswalk. I mean, I could walk acrossthe street here, I could. Alright, I passed. I’m not a robot. I’m gonna click Sign Up. Here we go. I’m gonna save that password. What if I turn on sync? All logged in as Big Papa. Here we go. So I’m going to click Agree. I’m going to pop back to the page, and you’ll see now this is filled out. Now one thing I do want to point out here is that my token here,my key is on the screen, and if a hacker were to pause my screen, and copy that down, they could essentially do thingsto my account on my behalf, but I of course know that, and I’m gonna delete this token later.Remember this is likeleaving your car keys on your driver’s seat. You probably don’t do that. So treat these keys the same, and keep them safe, and with you. So I could just copy this whole command, and paste that into my terminal, and it would work. We’ll do that in a bit, but what I want to show youfirst is that you can do this, Try It button here, and what happens is what comesback is this beautiful JSON. So you’ll see that what’s beingreturned here is as artists, and it’s an object that hasthe search that we built, and then here is this items, and you’ll see that it’s an array, because there could bemultiple artists named Lizzo, and I guess looks like maybe there is. Yeah, it looks like there’s actually another artist named Lizzo, popularity 88, and what’s this Lizzo’s popularity? Her genre is Escape Room? Man, I feel old. One thing we can do is we can look, and see if there’s these external images so you can kind of take a look, and see if it’s them.I’m going to click Go To Here, and we’ll see whathappens, and there she is. Lizzo is on all the time at our house. Once my daughter has figured out that Alexa could play music, they’re like play Lizzo,Alexa, play Lizzo. Alexa, by the way is aVoice User Interface, right? There’s the I again.So I’m gonna get back to our tab. And we will go now, and we see here that she has an ID, because we’re in this artist, right? So we see here that she has this ID. I’m gonna go ahead,I’m going to copy this, and you also see thatthere’s another API call here that we can do. There’s this HREF that willget her specifically, right? So there’s the /artist, and there’s /herID. So if we call that it wouldget information about her. Again, I’m gonna make surethat I copied her ID here. I’m gonna scroll down a little bit more. Think there’s the other Lizzo. Let’s look. I think there was a thingwhere we can look at the page. Yeah, here we go. So here’s external URLs, and you’ll see this as an API. This is the actualSpotify page itself stuff.So if I’m gonna do this,and I’m gonna right click. I’m gonna say, go to. This is Lizzo’s actual page, and this is how it’s displayed, right? As a web page on Spotify. If you scroll down here, we’ll see that there’s this popular, there’s her popular songs, Good As Hell, great stuff. If you don’t know her,use this link, learn her. I happened to know that we can get a list similar to these popularsongs using the API. So let’s go back to our reference. Okay, so we’re back here in our reference. Let’s look at the artist API. So we’re gonna click on Artists, and again, I’m going to go into the beta, whether they be a referencemight be what’s live for you, and I’m gonna click intothe Artists API over here.I’m gonna scroll down a little bit. So there’s get an artist,get an artist’s albums, and what else do we have? Get an artist’s top tracks. This is exactly what I wanted to do. Okay, so again, here’sthe docs about that. I’m gonna try this out in the web console. Okay, so get an artist’s top tracks. It’s gonna do a GET, and this is the end point. So we’re gonna just kind of, it needs that ID, right? So we’re gonna put that ID in there.It’s coming defaulted with somebody. So I’m gonna go ahead, andpaste Lizzo’s in there. Okay, and the country is US, and you’ll see that again, it’s changing. So see how the her IDs here, country’s US, and we’re gonna passour private keys along. I’m gonna click Try It. Alright, so now we’vegot a list of tracks, and each one of these trackshas what album it showed up on. Okay, so again, this’llbe in the same list, their top tracks as we saw on that page, which is super neat, right? There’s the, because I love you song, and let’s keep going a little bit. You’ll see how the URI’s here, they use a different style URI with the colons to separate, but it’s Spotify artist, and then the ID. And we’ll see here thatthere’s this preview URL, which you could actuallyjust go ahead, and open, and it will start playing this song.Pretty cool, right? You can get access to allof Spotify’s music library, and you can build toolsthat extend their platform. I highly recommend that you go, and take a look at what peoplehave built using these APIs. Super impressive. Did you notice how fastthose results came back? How could it do that search so quick? Oh, wait a second, does it even need to? The results don’t change all the time. It’s not like Lizzo is droppinga new song every minute. Though, I wish she would. Those results are definitely cacheable. Ding, ding, ding, Casheability is alsoavailable on the client, and we’ll get to that here in a bit, but this is a great exampleof a Layered System. I’m almost positive thatSpotify has set up things so that returns that same JSON from its own serverside caching mechanism. It’s not on every request. Now as a user of the API, I don’t know how it’s doing that, and frankly I don’t care. I want it to be available and fast when I hit that specific URL, and as Lizzo might ask,baby, how you feeling? I’m feeling good as hell.That was fast. Spotify is just one REST API. There are tons, and tonsof services out there. There are even servicesthat exist only as APIs. Let’s go ahead, and take a quick break. I’d love for you to take some time, and think about what youmight be able to build with the Spotify API. For instance, while I was using the API, I had this idea pop up. I’m often at festivals, and I’m having a hard time figuring out which band I should go see. There’s so many. I love to have an app suggest me which of the bands that are playing that I would most likely enjoy based on my listening cabinets. I’m pretty sure you could do that just by using the Spotify API, and a list of the bands performing.If you end up building this app, please share it with me. What other interests do you have that provide an API that you can use? Check the notes for more ideas after you come back from your break, let’s dive a little deeper, and make use of an APIusing our own tools. See you soon. No, really take a quick break. Seriously, it’ll do you good. No benching. (calming electronic music) While I realized that exploring an API on a website is informative.It might not feel like you’reactually using that API. I think the next logical step in exploring is actually making that requestyourself from your computer, not from a website. Let’s use a different API, this time let’s use Twilio. Twilio is a company that loves APIs. In fact, that’s mostof what the company is. It’s a company for developers that helps abstract awaytelephone communications, well actually all kindsof communication channels. It lets you bring communicationsinto your applications. It allows you to make, andreceive calls, and text messages, and a whole slew of other things. I need to be a littleupfront with you here. I love Twilio. I mean, I love it so much I even applied for a job with them, and I got it, but even if I didn’t, I would still show youhow cool their APIs are.I mean with a single commandyou can send a text message. I remember when I first did that, I was like, wow. That level of abstraction is amazing. How does that work with allthe different cell carriers, the varying standards, and networks? I have no idea, and I don’t need to, that’s the beauty of this API. Let’s get started. So I’m here at Twilio.com,and again a word of warning, this will most likely look different as Twilio is constantlymaking improvements. So please check the notesfor any changes to this flow. So first things first, let’s sign up. We’ll be able to use a free trial account for the rest of this course. Let’s sign up with my information. I am Greg Dennis, and againI’m gonna use that trick. So I’m gonna say CraigsDennis+let’s say API course, in case I’ve alreadydone that one @gmail.com, and I will set my password too, and I am going to acceptthe terms, and services, because I’ve read that. And I’m gonna start my free trial. Save my password.There we go, and it’ssent an email to my Gmail. I will go check that real quick. There we go. I’ve got a email, and I amgoing to click on that link. Let’s do this. And we’ll paste it here. Verify my account, and I am logged in. Alright, so I’m gonnaput in my phone number, which is (503) 461-5537, and this phone numberyou provide will be used for authentication for the Twilio Console. Somebody might contactme of free onboarding. That sounds great. I’ll check that. I’ll click Verify. So 708655. So in trial mode we can only communicate withnumbers that we verified. So do you write code? I do. I write code, I write Python code. My goal today I’m gonnause it in a student, or hackathon project for sure. I’m gonna send, or receive SMS. SMS is a Short Message Service, which is text messages.We’re gonna send text message. So the way Twilio works is youbuy an actual phone number. Well, let’s do it. So we’ll get this trial number here. This number got automatically selected. It’s fine by me. (201) 584-8089, and I’m gonna choose it. Let’s say Choose This Number, and just like that the number is mine, and I can program it, and we’ll do more with that later. So I’m gonna click Done. So there’s some notes here, right? You can only send messages, and make calls to verify numbers. That’s how our Twiliotrial account works right? Notice also, we have $15, which is more than enough money to do anything we’re gonna do in here, and it’s also says that messages, and calls include a noteabout this coming from Twilio trial account. Okay, that’s fine. What do you say we send a text message? Let’s do it.So the way that things work is over here, there’s a little menu, andwe have different things. As you can see, there’s abunch of stuff available. We’re gonna choose thisvery first one here, this programmable SMSshort message service. I am also going to pin that to the dock so that I can get to it easier. So it’ll always be there, okay? So, you’ll see here, it’s pinned. Well on this page, I’mgonna choose, Get Started. Let’s do it. Now, this step allowsus to explore the API like we saw on the Spotify site. You’ll see as I change things here so let’s change this body to say, ahoy, you’ll see that it changesthe code that’s over here. Fun note here, ahoy was the first wordever spoken over the phone. So ahoy is kinda likehello world of phones. So I’m gonna go ahead,and click Make Request, and I got the text. Of course it’s prefixed withsent from your Twilio number, but whoa, right, I just senta text by pressing a button.Let’s take this a step further. I’m gonna copy this code, and actually first before I do that, I’m gonna check this show your Auth Token. Just like Spotify,Twilio uses Auth Tokens, and their private keys, but I trust you, and alsoI’m gonna delete this later. I see you hackers. So now if I come over here, and I click this Copy icon here, it will be in my clipboard. Now I’m running on a Mac, so I’m gonna open up myterminal and I’m going to paste. So see how this is the URL that we are going to post to, right? We’re going to post, because we’re gonna becreating a new message.Notice here, this is my accountSID, or String Identifier, and because we have a JSON here, this .JSON, that tells theTwilio API to return JSON, and we use form a URL, and coding here. This is what this data URL, and coding is, and this is the two. We’re gonna send it to my phone number, and it’s gonna be from our Twilio number, and the body’s gonna be, ahoy. So I can come in here, and I can change this code, right? So I can, and instead of ahoy, I’m gonna make it say, ahoy from terminal, and this dash U here is setting up the authenticationof the account SID, and this is my Auth Token.So when I go ahead, and press Enter, we’ll get some information back, and it tells me that it was successful. It will give an error if it didn’t, I got my text message. So this command is sendinga post, which is great, but I can also use GET to receive the messages that have been sent. So kind of like a sent log. So what I’m gonna do isI’m gonna use the up arrow, and get the information back.I’m gonna change to GET, and then I’m gonna get ridof the rest of these lines, which I’m gonna do with GET in here, and do Control+K on the Mac. Look in the notes for howto do this in Windows. So we’re gonna say all of the messages that were sent to this, and if I go press Enter, that didn’t work, because I left the trail at the end, have to press up again. So I’m gonna get ridof this trailing slash, because that means likecontinue on to the next line. So here we go. Now, I need to have my account SID. So let’s do that again. Let’s go press up a couple of times.So I forgot that I need, we’re gonna need to keepour information there. So let’s just go ahead. I’m gonna get rid of all of these lines. So again, that’s Control+K, Control+K, and this is dash U, and we’re doing a GET to this account, and we’re saying all of the messages that were ever sent from this account, let’s take a look at that, and we’re doing a GET, sowe’re not doing a post. So we’re gonna show a list. There we go.So again, you could format this, or make it prettier, but for now though, let’s keepexploring some more tools. Awesome job getting thatrunning on your local machine. It feels pretty good, doesn’t it? What a cool skill you now have. You can send a textmessage from your machine with just a single command. Now, believe me, this is just the tip of theiceberg of what you can do. There are so many moreTwilio APIs available, but for now let’s takethings a step deeper. I don’t know about you, but I’m a little clumsy when it comes to longcommands on the terminal like we just did with Curl. When exploring API’s, I really like to lean ona tool called Postman, and I think you’ll enjoy it too. Why don’t you take a quick break, and then we’ll check out Postman? (calming electronic music) Postman is a wonderful feature rich tool that I use all the timeto explore new APIs.It started out as a Chrome Extension, but recently became afull fledged application. It’s super handy. I love how it can help youorganize your learning, and I think it’s an excellentexploratory tool too. Let’s dive in. Postman can be downloadedat GetPostman.com. Go ahead and pause mewhile you get an installed. This right here. Download the app, and I’ll wait, and when you’re done un-pause me, All set? Okay, so here it is. I’ve got an installed too, and when it comes up itwill have this Create New, and typically when Iend up using this tool, I’m working with a specific API, and what I’d like to dois to create a collection to keep all of the requeststhat I make grouped together. So I’m gonna choose Collection here. So Create New Collection. Let’s recreate those calls that we made to the Twilio API using Curl. So let’s do that right here. So we’ll call this the collection name is gonna be Twilio, and then I’m just gonna click Create.Down here there’s a little window thing, a little bar over here. You can see that you’ve gotyour collections over here. So we have a new one here called Twilio and in here you’ll seethat we can add requests. So I’m going to go ahead,and click Add Requests. So let’s build that message log. Remember that was the GET thatwe did over in the terminal. So I’ll name this request, that request name is message log, and I like to make a description here about what’s going on here. So this is gonna be allmessages sent from my account.That’s what we were looking at, right? That’s what that message log was, and if I’m taking notes, usually what I do is I dropa link to the documentation about what the resourcesthat I’m looking at. That way I have a quick way toget back to it to look at it. So one way to do that is justgo find the documentation. So if we just do Twiliomessage resource doc, that’s what I had there before. So that’s gonna find theresource for the messages, and a resource reference. That’s great. And the way that the code here works here is very similar to like we saw on Spotify, the different things that are available. There’s the create message resource, and each one of these kind ofhas its own little heading, and there’s some code overhere that we can switch. So I want to look for list all messages. That’s what we want withthe message list, right? So I’ve got this example, and I’m gonna grab the URL, and I’m gonna come back over to Postman, and just drop it in there, and a Postman uses, here, this is marked down.So I’m gonna use brackets,and say Twilio documentation, and then if I put parens,I can paste the link there, and that will make alink inside of my notes. Let’s scroll down a little bit here. Twilio offers a ton of different API, so I could break this down even further with this thing called a folder. So let’s open this up actually, and let’s make a new folder here, because you know, there’sso many different APIs, we might be playing with a bunch of different things.So what I like to do isput these in folders. So let’s make a folder. We’ll make the folder called SMS. Okay, and we’re gonna addthat to the SMS folder. Okay, so what does the saying is we’re gonna make this new request. We’re gonna create anew folder called a SMS, and when we click Save, we’ll see that here underneathTwilio we have this SMS now, and there’s our message log as it were.And so what’s happenedhere is it’s created a tab for our new requests that we’ve made, and you’ll notice thatthere’s a little twisty here, and there’s a tab, and there’s the link to my documentation, which is handy as you’ll seeas we’re going through this. So let’s go grab that URL that we had. I’m gonna go back to my terminal, and I’m gonna press the up arrow, and I have that there. If you don’t have this go ahead, and look in the notes, and I’ve got a copy for you. So I’m gonna copy that. I’m gonna come here, I’m gonna put the request in here. One thing to notice over here is there’s this dropdown that says GET, and we can send different types of, here’s the different verbs, right, that we can send acrossHTTP verbs, a bunch of them, and we’re gonna leave it at GET right now, because that’s what we’re gonna do.We’re gonna get the messages, and I think we’re all set. So let’s go ahead, and click Send, and oh we got an error. You’ll see that we gotback a 401 Unauthorized. So if I mouse over it, I see more information, which is nice, and if I scroll down here a little bit, here’s the error messagethat came back from Twilio. It says your account SID, or Auth Token was incorrect, and oh yeah, we didn’t even pass them.So you can add thatauthorization to your request by this little tab here. So next up param, this is authorizations, and here we’ll say typeinherit Auth from parent. Oh, that’s actually a great idea. We’re gonna be using the same account SID, and Auth Token anyways, so we should just use itfrom the parent, right? So I’m gonna open up my Twiliocollection, which is here. So if the screen ever gets closed, this little guy here pops out. So I’m gonna go to my Twilio collection, and right click on the buttons here, and I’m gonna choose Edit.Here we go, and we’ll comeover here to authorization. So what this does is all requests, will share this if they have, you know, inherit from parents. So we’ll get this authorization. It’s used for everyrequest in the collection, which is what we want, and we’re gonna change thetype to be a basic Auth, which is what we’re using there. So we’ll click BasicAuth, and look at this. We were gonna put our supersecret information here, but it’s saying heads up. These parameters hold sensitive data to keep this data secure while working in acollaborative environment. We recommend using variables. I don’t know about you, but whenever I see a security warnings, I like to follow that. So let’s follow that. So let’s, there’s variables here. So it says, learn more about variables. If there’s also thisVariables tab up here, right? So let’s click into Variables.Okay, so what these dois we create a new name, and it will have a value, and people can set ontheir own machine there, these own values. So this is a good way of not accidentally sharing out your keys. So the things that we want is we want to have the account SID, which is a string identifier. So Twilio account SID, and the way these these work is, there’s this initial value. This is what people willsee when they come in. So we want them to fill out their own. So we’ll say your account SID. So if anybody is using this, you’re gonna share it. That’s what they’d see, and we’ll get the current value. So that’s over in my Twilio console.So if I go to Twilio/console, which is the main page, once you log in, you’ll see here thatI have my account SID, here it is, and then there’sa little copy button. So I’m gonna copy my account SID, and we will paste that, and the current value is my account SID, and then we’ll do another one. We need the Auth Token. We’ll say Twilio Auth Token it will say your Auth Token, and again, what we wantis this Auth Token. I’m gonna copy that. And paste that here. Awesome, and I’m gonna click Update. So I’m gonna go againagain, and choose Edit, and I’m gonna go to Authorization, and now that we have it, Postman allows you to use those variables wherever you want to, and you can replace themby using a curly brace. Sometimes those are called mustaches. If you look at that sideways. So we’ll do Twilio account SID, right, so it’s double mustaches, right? So mustache, mustache,and then it does that.So mustache, oops, and for the password, we’ll do Show Password just so we can see thatwe’re doing it right. We’ll do mustache, mustacheTwilio, Auth Token, that’s how this works. So there we go. So that is going to set the authorization for all of the collectionsto these variables that are local to our machine. Make sense? There we go. So we’ll click Okay. Update, and now let’s go ahead. I’m gonna close this window here, this little nothing, andI’m gonna click Send. Okay, so we’ve got theauthorization headers in place.We’ll click send. There we go, beautiful. Much nicer formatted. See here we got our messages, we’ve got an array ofmessages that came back, and we have ahoy from terminal, and we should have another one. Now, there’s nice URIs that wecould go look at other things like feedback that came or the media that’s attached to it, and here you’ll see the originalthat we did that was ahoy, and you’ll see that the costof it was 0.07 of a cent. So awesome. Now that we’ve got all ofour foundations set up, we’ve got our collection, and we’ve got our variable setup, let’s go ahead, and let’s make it so thatwe can send a post from this right after a quick break.(calming electronic music) So we’ve got our messagelogs all set up in Postman. So now let’s use it tocreate a post request. Now since we want to usethat same authorization that we use in the message log, we should put it in thecollection, and folder. So let’s go back over here. Again, if this is closed, you click this little likeI hit to pop this out. So we’re gonna add a new request inside of the Twilio SMS here, and we’re gonna make Add Request, and the request name isgoing to be Create a Message. So we’ll say creates a text message, and then I’ll see if I havethe Twilio docs up still. I don’t, so we’ll have again, we’ll search Twilio message. There it is filling it out for me. Message, resource reference. And over here on the left nav we can see that there’s different bits. We want this create a message resource.This is definitely what we want. You see there’s the URL. So we will copy that, and bring that back over to our Postman. It will say Twilio Documentation. Awesome. And it’s in the SMS folder, because that’s where I started it from. Let’s bring this all the way up, and we’ll say save to SMS. That’s the folder. Awesome, so we have this Create a Message. So let’s see in order to create a message, remember we’re gonna do a post, and it’s that same URL that we were using fromthe get message log. So see how there’s two tabs here? So I’m gonna switch back over to my GET.Oh, look at this. We see here that theaccount SID is in there, and we don’t necessarily want to put our accounts SID there for each one. We want anybody who usesthis to be able to use it. So let’s change that touse a Twilio account SID. So that way we’ll use thevariable that we’ve created right? So that’s gonna replacethat automatically here, and then you can see whatit is by mousing over it, and now let’s click Send, and make sure that we got it. Cool, now this is a usable URL for anybody if we were ever to share this. I’ll show you how to dothat here in a second. So we’ll paste this here, and when we’re creating a message, we’re gonna need to send some additional information, right? So if we click over here, and we click on this body tab, so we’re gonna send some values, and in the Curl command we sent that using a form URL encoded.So let’s do that. What were those values though? Oh, you know, I should popover to the documentation. I am sure glad that I madethat link so I can click here. Open that up. Cool, so we definitely need a two. That’s right, we need a two from, so you may also need to pass a body, or a media URL with a messages content. Media URL, does thatmean I can send pictures? Cool, we should do that, shouldn’t we? Cool, so there is two, and there’s from, body, and media URL. Okay, cool. Now I’m gonna set this tothe Curl and because you see these differentprogramming languages here, we’re gonna set this to Curl. So it’s in the right format here. So there’s media URL, and the two in the fronthalf capital F’s there. So that’s the format that we want.So we’ll say two, and that’s my number thatwe want to send this to. So this 1-503-461-5537. So let’s add a body. So we’ll do body again, need to make sure that it’s checked. So body, and we’ll say sent from Postman, and you can actually send, in these messages, you can send emojis, which who wants a textmanager without emojis? My frequent used one is the mussel taco. Frowny love rocket, sentfrom Postman, awesome, and why don’t we send a media URL? We saw that there in the notes. So we’ll say media URL, and the URL, we can send any sort of aGIF, or Jif, or a whatever, however, whatever you cansend here whenever you want. I’m gonna copy, and paste one of myfaves that we can send. Feel free to use your own image. I’ve left some funsuggestions on the notes, if you want to copy. Giphy is a great site to find those. So let’s see, we get to body media. Now, we need from, we need from, so that’s our Twilio number.So I’m gonna click in here, and I’m gonna say from actually, this is something where, this is my personal number, so why don’t we add a variable for that? So I’m gonna flip back over here to the Twilio variables. So we’ll come back to edit, come in here to variables, and we’ll add a new one forlet’s call it Twilio number, and I’ll say your Twilio number, and our Twilio number. Let’s look at that, andit’s in the console. So Twilio/console,here’s our trial number, that’s what we want.Copy, and paste that, and we’ll paste that here. Here we go, say Update, and so the from value wecan use Twilio number. Awesome. Alright, this is feeling good to me. Here it goes, nothing. We’re gonna click Send, and boom, 201 created awesome, and I just got my textmessage, and there’s my GIF. Pretty cool, right? So creating an MMS, or multi messaging servicemessage is a lot more difficult than this if you were toattempt to do that by scratch, but the abstractions in place, right? So it was pretty much seamless for us.Now you’ll notice herethat the message says maybe you won’t notice thestatus here says queued, but if we go, and welook at our message log, and we run this thing again, we can see that they’re sentfor Postman, there’s our emoji. And here’s some more information, and if we scroll down a little bit more, we’ll see these sub resource URIs and now we can see thismedia that was sent along.So let’s go ahead, and I’mgonna just click this link, and watch what it does. It’s gonna make a new GET requests. Now there’s a bit of a problem, because this GET request isoutside of our collection. So typically when I needto do something like this, there’s a little hack that you can do so I can get theauthentication information. So let’s just click Save, and I just call it, you can just call it that if you want to, and then I’m just gonna call it temp, because we’ll delete itwhen we’re done here. So we’ll just call it Temp. Say that to SMS, and when we run this, we’ll see that we gotback the list of medias, and because you can send multiple, right? You can send multiple pictures in a, and we’ll see here thatthere is an official one, and see how it is accounts,and then messages, and then media there.There’s sub resources. So I’m gonna go ahead, andI’m gonna click on that. And if we wanted to, wecould run this request, and it would be, it would show information about the media, but if you actually remove this .JSON, it will show the form ofwhatever the media was. So we’ll make this request, and watch what happens. Let’s see, we got back my GIF that I sent. And with a request of this size, we probably don’t want tobe making that request again if we don’t need to.So this sounds like the jobfor client side caching. Well let’s see if our APIsupports caching tricks. So what I’m gonna do is I’mgonna expect the headers that are on this response. Nice, so it has this lastmodified header here, which is a good sign thatit does support caching. So let’s go ahead, let’s copy this value. So I’m gonna copy this datehere into the clipboard, and if I go up to wheremy request was made, if I come into headers here, I can add a new header,and I’m gonna say if, and you’ll see that Postmanis doing a really good job of showing you what’s available.So if it’s been modified since that time, because this is basically whatyour client would do, right? It says, if this thing hasbeen modified since this time, then show me anyone, otherwise don’t. So that’s what this does. So I go in, and go ahead,and I’m gonna go ahead, and click Send, and you’ll see that my APIreturned this time not modified. So our API supports caching, which ding, ding, ding, means we covered another partof RESTful API constraints using standard HTTP caching mechanisms like last modified, and etags, a RESTful API should support caching.It’s up to you to maintainthe cache on your client, and decorate your request, but this can come in really handy to avoid making unneeded requests. Awesome, so let’s make surethat we’ve got these saved. Do you see these little orange dots here? Means that they haven’t been saved. So I’m gonna click on it, and click Command+S, or Control+S, and I don’t really care about the temp, and I don’t really care about this one. That was just kind of exploring. So let’s take a look here. We have this temp, we canchoose, and say Delete, and we’ll delete it from temp, and now he has this, have our message, and our create message. One more quick thing before we wrap up. I wanted to show you, you can actually generate code from this. So if you click in here, you can see, here’s an example ofgenerating a code snippet. It’s gonna actually run through the code, and set up everything thatyou need to run this code.Now there are thingscalled helper libraries that will do this, and Twilio has one, and we’ll look at that here in a second, but this is pretty slick, right? Really, really powerful, and you just copy it tothe clipboard, and boom. Pretty powerful, huh? Awesome job diving into Postman. It’s a super powerful tool, and it keeps getting better every day. There are so many featuresthat we didn’t even cover. We barely scratched the surface. Check the notes for where to learn more. We saw how to organizeour requests together into collections as well as share common, and secure values by using variables.We learned how to add differentvalues to your requests, both in form, values, and headers, and we also saw how to navigate through various subresources by clicking URIs. We even saw how to create actual runnable code from your request. While we were in the Twilio documentation, you might have noticed the code examples on the screen. On that page, it’s possible to tab between various languageimplementations, and solutions. Many products offerwhat is known as an SDK, or software development kit, or Helper Library thatallows you to interact with their product inyour native language. As you can see, it abstracts away the REST API completely. Let’s take a look at theTwilio Helper Library next. Before that though, just a quick reminder to make sure that you checkout the notes on this video.There’s a link to a repositoryof built out collections that are ready for you to use. There are lots of greatAPI’s to practice with. Postman and Curl are bothgreat tools for accessing, and exploring APIs. However, when it comes time, most likely you’re gonnaneed to write some code. As we saw in Postman, youcan actually generate code. All programming languages come with some sort ofway of making requests, and as you know, HTTP requestsare all we really need to interact with REST APIs. Now writing that sortof code is totally fine, but you’ll find outthat you end up writing a lot of what is knownas boilerplate code. Now, by boilerplate, I meancode that is repetitive, and almost always the samejust with a few tweaks. Many products, and serviceshave created a solution to help you avoid this problem. They’re often calledhelper libraries, or SDKs, Software Development Kits. They’ll be specific toyour programming language. These libraries help to make your code more concise, and legible. They usually also provide additional documentation for your editor, which I find super handy.Let’s go check out someof these helper libraries. Let’s explore both JavaScript,and Python Helper Library. In order to do that, I’d like to make surethat you have both Node, and Python installed under computer. I’ve put installationinstructions in the notes. Let’s get started with Node. So I’m gonna open upthe terminal on my Mac, and I’m gonna make adirectory called scratch, and I’m gonna change into that directory, and in here I want to make adirectory called JavaScript, and I’m gonna CDN to that directory, and I’m gonna open my editorin this directory here.So let’s say code. I’m using Visual Studio Code. So we’re gonna open up Visual Studio Code, and over here in our directory, I’m gonna add a new file, and I’m gonna just call it explore.js. Alright, now what I’m gonna do is I’m gonna install the library in Node land that is called NPM. So I’ll open up a little terminal here in Visual Studio Code, and I’m gonna run NPM, install Twilio. And that’s gonna go out, and it’s gonna get thelibrary so that I can use it, and I can use it like so now, now I can say const TwilioGoals require Twilio. And then we’re gonna initialize it. So we’ll say constclient equals new Twilio, and as you can see, it takes an account SID, and an Auth Token, and I have those available for us here.So here’s my accountSID, I’m gonna copy that, and we will make theAuth Token after that. Alright, so we’ll put that, awesome. Now can you think of anythingwrong with doing that with putting my accountSID and Auth Token there? Well, right now this isjust sitting on my machine, but if I were to upload,or share this with anyone, my credentials are sitting right there waiting for anyone to steal. Typical solution here is touse environment variables, and we’ll do that whenwe build our application, but this is just a friendly reminder.Be careful with the keys. What we’re gonna go over here might very well be overwhelming, but it will make sensesomeday if you stick with it. I promise, oh, I’ve added notes, but really don’t let this stress you out. The reason why I’m talkingabout this behavior is, because the Twilio JavaScript client works like most JavaScript libraries. It’s asynchronous, and it relies on a concept called promises. So the way the promises work is that you set up handlers for when your methodcall actually completes. So to get our messagelog, we use this method.There’s a method called, so we do client.messages.list, and what that method returns is an object that is called a promise. It’s a promise of a future value. The future value in thiscase will be our messages. So promises have animportant method on them, and it’s called then. So I’m gonna go ahead,and chain on that message. I’ll say .then, and this methodshould be given a function that accepts of value. So I’m gonna pass it a function. Now in modern JavaScript you can use what are knownas fat arrow functions. So what I’ll do is I’llput the name of the value, and the value here is messages, right? Because this is what I’mexpecting to be returned, and then I’m gonna put a fat arrow, which is an equal sign of greater than, and then I’m gonna put the function body.So let’s just log outthe most recent message. Okay, so we’ll do a console.log, and I’m gonna use back ticks so that we can get a string interpolation, and I want it to be thefirst one in the array. So we’re gonna say the most recent message is dollar sign, curly brace messages, zero,because it’s in array.body, and that is a long line in, this happens quite a bit. So typically what we do is when we do this chain, is we press Enter here, and we put that on its own line, still pretty long still off the screen, and if I ask this to format with prayer, let’s see what it does.There we go. Let’s see, you know, it’s done a pretty good jobof getting things close. So, and then again, just to show you that thisis running asynchronously, I’m gonna below making this call, right? So this is, looks likeit’s after that calls made. Well it is after thatcall is made is just, that call’s gonna be asynchronous. I’m gonna say gathering your message log. So let’s go over it real quick. What’s going on here is that we are gettinga hold of the client, and we’re setting up a new client so that all requests made against this client areauthenticated, right? So that’s our accountSID, and our Auth Token. And then we’re gonna use the client, we’re gonna use the messages out there, we’re gonna do a list, and that list is an asynchronous method.Now while this has been abstracting away, we know what this is doing. It’s making that same GETrequest that we did in Postman, and in Curl, and we know that it willreturn a JSON response, but because this is asynchronous, immediately it’s going tomove on to the next line. It’s gonna say gathering your message log, and when that call to list returns, it’s gonna run this function, and it’s gonna pass in the return value of that response to here. Now you should note the return value here is an actual object. It’s not a JSON response. That sneaky little Helper Library of ours has also abstracted that away for us. It took that HTTP response, which has a body of JSON in it automatically turned itinto an object for us, and you can see that here, it’s an array of objects, right? So that’s at the zeroth,okay, so let’s run it. So I’ll do clear down here, and we’re gonna say Node explore.js. So we should seegathering, or message log, and then the most recentmessage, fingers crossed.Here we go. Awesome. Yes. Okay. Now, one thing that weshould make sure to do here is to capture any errors that might have happened asynchronously, right now if an error happens, it’ll be swallowed. Well actually, let medemonstrate what that means. This bites me all the time, and I don’t want it to bite you. Let’s say that you accidentally trimmed the last characteroff here, the seven of mine. Let’s take the last one off here. So I’m just gonna do that.So it’s an invalid SID, and I’m gonna save, and I’m gonna run it, and it’s gonna saygathering your message log, and then it’s just gonna endout no error, no nothing, but the results never came back. So what we need to do is we need to catch anyerrors that might occur. Every promise has a method named catch, and what might not be clear here is that this then here, that’s returning. This is actually also a promise. So I can just chain on here. So I can say .catch, and I’m gonna catch an error, and again, fat arrow function, and we’ll just log that error.So I’ll say console.error.E-R-R. Okay, so now we’ve got, it’s gonna chain, and if anything happens,it’s gonna send the error. So let’s try that again. Let’s see what happens nowwith our catch in place. Awesome. It tells us that it wasn’t found, because that’s wrong, right? Great. This is probably a good time to remind you if that was way too muchinformation that you can, and you probably shouldscrub the video back, and watch me do it again. I guarantee that you’ll catch some stuff you missed the first time, and at the very least, you’ll spot a dad joke that I made at the very beginning of this video.I had said, this willmake sense eventually. I promise. I’m sorry. I’m kind of obligated to make that joke, and if that doesn’t makesense yet, that’s also okay. Check the teacher’s notes formore information on promises. Let’s change gears, and take a look at the Python version of the Helper Libraryright after a quick break. I know I need one. See you soon. (calming electronic music) We just took a look at the Twilio JavaScript Helper Library, and now let’s take the PythonHelper Library for a spin.Now, if you don’t havePython installed, pause me, and check the teacher’snotes for instructions. In my terminal, from my scratch directory, I’m gonna create a new Python directory. So mkdir Python, change into that, and while we’re here, let’s just check, and make sure that we havethe right version of Python. So I’m running Python 3.7.3. As long as this first threehere is a three, and not a two, we’re good to go. Python uses the conceptof virtual environments. These allow you to install packages local to this application. So let’s do that just to be safe. So, that’s done with the dash -m, and then venv, for Virtual Environment, and I usually just call that .venv. So that will create a directory called .venv that is right there, and here we go, and what happens is now I’m on a Mac, so this might look a littlebit different on Windows.If you do .venv, there is a directory called bin activate, and I’m gonna source that file. I think that’s a .bat file on Windows. Check the notes, and you’ll see now that I am activated. So I’ve got this .venv here. I’m gonna go ahead, and open up my editor. So I’ll do code doc, and here we are. There you can see my .venv directory, and I’m gonna add an explore.py. Alright, and I want to installthe Twilio Helper Library. So I’ll do a Control+Tab, and you’ll see that myeditor actually went ahead, and ran that argument for me.So I’d already, I’m activatedhere, which is good, because I want to installa package here using PIP, which stands for theAcute Recursive Acronym of PIP installs of packages. So that’s PIP install, and again, Twilio. Cool, so it’s installed,and we can start using it. So I’m gonna go up here, and we’ll say fromTwilio.REST import Client, and we’ll make a new client, and again, it can be instantiated using so here it’s given usthis nice information that’s available about the API. So we’ll put a, I’ll put in here again, this is our account SID, and boy, it really wants toshow us that account SID, and Auth Token. So let’s get that.So again, account SID, and Auth Token. Let’s get these on some ofthe new lines by themselves. Again, really bad practice toleave your keys out like this. We’ll fix that in a bit. Now let’s print outthe call log real quick just to show off the similarities, and differences between the libraries. So the Python versionis synchronous, right? So we can say, so we can just iterate through those lists, and messages. So we can say for messagein client.messages.list, and we will say print the message.body. Alright, let’s see what that looks like. So we will do Python Explore.py and I didn’t save it. So that’s an importantpart, Python Explore.py, and there we go. Sent from Postman, Ahoy from terminal.So awesome, So let’s go ahead, and we’ll comment that out for now, because we’re gonna do something else. So those are commented out, and let’s write somecode to send a new one. So we’ll say message equalsclient.messages.create, and in here we are goingto pass our variables. So we’re gonna send this to me, or to you in this case, (503)461-5537. It’s my number, and the from, now you’ll notice that from isa key word in Python, right? So see like from Twilio? So what’s nice is thePython library has made it from underscore here.It helps for the reserved words. So my number, my Twilionumber, what was that? Here it is. That’s my Twilio number. Awesome, and let’s do a body, and we’llsay body, hello from Python. Yeah, let’s go ahead, andlet’s print things out. So Python has a nice littlething called F strings which will allow you to printvariables that are in scope. So we’ll say if created a new message, and let’s just show the message SID to make sure that we got it, and we can just do msg.sid. Hey, so it starts with an F, and it uses the mustachesaround this for message.sid. Very similar to those stringliterals, and JavaScript. Let’s go ahead, and create this one. So we will run Python Explore, and this should senda message, and it did, and again, I want you to see we are abstracting away the fact that we’re posting to the messagessub resource under my account.It’s just magically happening, because we’ve logged thisclient in pretty cool, right? The other thing that thisabstraction gives us is we have instance variablesthat represent our resources. Now, it might not have been clear up here when I looped over these objects, but they’re actual objects. It’s not just data. They actually have methods, and I can call the deletemethod on this message, and it will get deleted. In fact, that’s not a bad idea. We’ve been doing a lot oftest exploratory messages. Let’s just delete them, okay? So what I’m gonna do isI’m gonna come up here, and I am going to uncomment this code and I’m gonna comment outour creation message code, and let’s make this an F string here.So we’ll say deleting message body. Here we are. We’re gonna say message.delete. Cool. Now before we run this, I want you to make sure that you understandthat we’re gonna delete all the messages in your account if you’ve been using a live account, and have things that you want to save, I highly recommend not running this. Okay, you’ve been warned. So here we go. I’m gonna update this. There we go. So we’ve just deleted all of our messages. So if we come, and try to run it again, you’ll see there’s nomessages to loop over. We’ve done it, clean slate. It’s like the nothing never was. Pretty cool, right? That Helper Library was able to abstract away the HTTP delete call, and it used the informationthat it had available in its object to make the call itself. Awesome. You see how the helperlibraries are similar yet match the development workflow, and style of each language? This is one of the key benefits of helper libraries in general. They abstract the way theHTTP client connection of the REST API boilerplate.They also behave as youexpect them to behave. It feels natural. The way that we were able todelete from the resource itself helps to unlock anotherREST API constraint scavenger hunt item, andthat is uniform design. Now this constraint has four sub sections, one of which is what we just discussed. Resource manipulationthrough representations, because there was enoughinformation included, it was clear how to modify, and delete this resource. Another sub section in here is resource identification in requests. Those are the URLs that are included, because of the URIs are included, we know that we can get, and manipulate specific resources. Uniform use of the HTTPverbs is pretty powerful. We just wrote some scripts that make use of helper libraries. These libraries are super handyfor automation based tasks, or batch scripting, making a whole bunch of calls at once. When we’re talking about this, we should cover another common tool for talking to external API’s, and that is the C-L-I, or Command Line Interface.There’s that I again. Command Line Interfaces canbe used to make API calls from an executable on your machine. More, and more these are showing up for all sorts of tools thatrequire authentication, and do a bunch of different services. This concept is popularamongst cloud providers where setting something upneeds to be done quickly from the command line. Check the notes for more. Another commonplace whereyou’ll use helper libraries is from within applicationsthat you’re building. Let’s get to the finalunit of this course, and implement an external API into existing web applications. You’ve got this.By now, I hope you’re starting to see that external APIs allow you to add pretty incrediblefeatures to your applications. Want to send a Slack message when someone fills outfeedback on your website? There’s an API for that. Want to change the color of your lights in your house when your favoritesports ball team scores? There’s an API for your team, and for your lights if you want it.Want to send yourself a text message 10 minutes before your bus shows up? APIs are there too. Heck, do you want to make a Furby dance? It’s got an API. They’re everywhere, andgive you lots of power. We’ve seen how to use themfrom the command line, and we’ve seen them used in scripts, but now let’s take a look at embedding them in a web application. I’ve gone ahead, and build the starts of webapplication for us to play with. Now, one thing I know I don’t do enough of is to compliment my friends,and family, and even coworkers.Sometimes the web can be so negative. So I was thinking, what if we made a web appthat did the opposite of that? Introducing Complimenter. So the way it works isyou fill out a web form for who you’re complimentingalong with their mobile number. You say why they’re great, and they get a text messagetelling them how great they are, and an encouragement to do the same, and of course they will,and when they come, and see the messages that havebeen sent by everyone else, they’ll be pleasantly surprised. Pretty sure we have a viral success here. So if there happened to be anyventure capitalists watching, that’s my phone number there. Now if building, and deploying a website feels a little too muchfor your current skillset, have no fear, I’ve created a coupleof repositories of code that we’ll be using. We’re gonna use a fun, approachable tool calledGlitch to host our websites. The website is basically functioning minus our API that we’re gonna add. If you haven’t used Glitch before, it’s a collaborative communitybuilt around learning.You take existing projects, and you remix them. It has an online editor. So I want you to head over to Glitch.com, and create a user for yourself if you haven’t done so already. After you’re all set, let’s get to adding ourAPI to the application. First, let’s take a look at the Python based web application. We’re gonna be using a webframework called Flask. Flask provides an API thatlets you extend the framework to create your application. This example application is going to be doingserver side rendering. This means that the pages will only be created on the server side. Any change, or navigation willrequire a full page reload. In the notes, I’ve included a link to the repository where I’ve got our starter code. So go ahead, and copy that. Now I’m gonna open up Glitch.com, and I’m gonna choose New Project. From here I’m gonna chooseClone From Git Repo. In here, I’m gonnapaste what I pulled out, and I’m gonna do, thisis the one for Flask, so I make sure that’sthe one that says Flask.I’m gonna click Okay. I’ve been having a coupleof problems with this. Sometimes this will just sit here, and say loading project. If it does, just try thatsame thing a couple of times. Let’s see what happens here. Sorta times out a little bit. I guess it’s safe to saythat Glitch is Glitching. Now, that’s not fair. There must be some sort of bugthat’s happening right now. I’m experiencing it. I’m wanting to record this just in case you run into itto just do it a couple times if that happens. I do want to point out that it is pretty amazingwhat Glitch is doing. It’s pulling us over. It’s sending up a wholenew environment for us in a web server that can run, and I actually have onethat’s up, and running. I did the same thing whereI made a new project, and you’ll notice I’m not even signed in, so that’s fine. They let you not even sign in, and create these things.Okay, cool. So here we are. Down here under tools, there’s a thing calledlogs that you can open up, and it will show you what happened. This is what happened though. It’s set up our web server here, and you’ll see that theserver’s actually running, and if you come up here, you can, and click on Show, and the sunglasses here. Your future’s so bright,you’ve got to wear shades.So you can click View in a New Window, and you’ll see that theapplication is up, and running, which is awesome, right? And this URL here, this is all yours, you can use it to do whatever. So the application itself,it’s pretty simple. It’s just a page with a form,and this section in here, provides messages whenthey eventually come in, but as of right now, we don’t have any, because we just erased all those, right? But as of right now, we don’t have any wayto send text messages. We don’t yet have theTwilio Helper Library installed in this application.So let’s go back over here. So these are the files thatare available over here. So you can see here is app.py, and there’s some settingsthat you can do up here. You can come in here, you can actually change the name of this to be whatever you want to be. So I’m gonna call this Complimenter and we’ll say compliment your friends. Cool, and this is anothernice thing you can do is you can change the theme. I’ll put it on dark theme. I don’t know when you’re watching this, but this should be okay,both in light, and dark.So there you go. You can also delete this if it’s not something that you want, if you ended up creating something. So cool. Awesome. So this app.py, this is our program. Flask works by creatingan object called app. So you do this Flask name, and it creates this thing called app, and then what you can do is you can put different routes in here. So for instance whenwe go to forward slash, which is the index page, right? It’s gonna do a GET, and it’s gonna render thistemplate of index.HTML, and that is in here understatic templates, index.HTML, and you’ll see here, thisis how the page is laid out. There’s some dynamic data here. We’re using some if, and it’s gonna loop throughmessages should they exist, and we’ll look at how that works here, and then we’ll see there’s a form that’s doing a post to add compliment.Let’s look back to app.py, and see how these two line up. So it’s gonna come in,and it’s gonna call, get sent messages, and get somemessages is not implemented. I left this here as a to doso we can fix that as it goes. So, and then it basicallypushes those messages, and sends us an empty list. It will just go. So in here we can see thatthere’s an add compliment, and it’s a happening when a post happens. So it’s gonna run thisfunction when a post happens, and again, that post washappening from the form, and we’ll see what’s happening is it’s just pulling off these variables is we’ve got sender receiver compliment that’s pulling off a two, and if we take a lookat ’em back out here, if we look at our form, wewill see that we’ve got, there’s the two, andyou’ll see the name is two.So that’s what’s getting pushed across, and their sender, andreceiver, and compliment. So they’re pulling us through. It’s kind of building a message for you. So sender says, and she’s using that F string right? Sender says receiver is compliment, see more at request.URL, and we’ll send that message to body. So it’s gonna call, send message, and right now send messageis needed to be filled out. So this to do here is actually a pretty goodplace to start, right? We need to send the text message, otherwise there’s no messages to show, and we know how to send text messages using a RESTful API, no sweat. We can do that. So I could use the Python HTTP client, and write my own messages. That seems like a lotof extra work, right? So I’m gonna use theTwilio Helper Library.So in Glitch you can access the terminal from your application by down here. If you go into this clip tools, and you come up here to logs, and then come over here to console, and see that I’ve nowgot a terminal running, which is pretty powerful, right? So I’m gonna type source. and then it’s .venv/bin/activate. And remember we had done that before.So we’re gonna activatescript now we’re activated, and you’ll notice that I’vegot this this year, this venv. So now I will go ahead, and I’ll do a PIP install Twilio. So we’ll get down thatTwilio Helper Library so that we can use it in this application. Awesome, so it’s all installed. So we should be able to use that. I’ll go ahead, andclose this, and it went, and it downloaded everythingthat we needed, right? So it got it, but if someonewas to come along later, and use it the way that itknows what to install is there is this requirements.txt file, and you’ll notice theTwilio stuff isn’t in there.This is just got the stuff for Flask, Jinja’s part of Flask, and Werkzeug is also part of Flask. It’s got just the stuff that was needed so they won’t have the Twilio Library. So we want to get theTwilio Library in here. So the way to do that is let’s get back in here into the console. So first again, we’re gonna activatesource/venv/bin/activate. Okay, so we’re gonna use PIP freeze to show all of the packagesthat we have installed, and then we can store its output, and we can do that inthis requirements.txt.I’m gonna go ahead, and do that, and when you make a change in the console, you have to do refresh tomake sure that it shows up. So now if we look in here, we will see that we haveTwilio is now available for whoever comes to use this later. Cool, let’s write some Python. Okay, so back in app.py. I’m going to come in here, and I’m gonna say fromTwilio.rest, import Client. So this line here, this load.env will loadenvironment variables from a secret Glitch file thatI have over here this .env. I started it for you. Now why don’t you pause me, and go get your keys, and phone number, and fill this file out. This is kind of like the environments that we saw in Postman. So go get those. Do you know where they’re at? Go ahead, pause me, and when you’re already unpause me, and I’ll show you how I did it. Ready? Okay. So here’s how I did it.I wait till my Twilio console, and I copied my account SID, and then I went, and Iwent to my Auth Token, and I copied that, andI pasted that there, and then of course my TWILIO_PHONE_NUMBER is my trial phone number right here, and I’m gonna paste thathere, and save that, except I don’t need that. There we go. Cool, so let’s flip back to app.py. And if we take a look here, there’s a thing calledTWILIO_PHONE_NUMBER, and it’s using this os.getemv for a GET environment TWILIO_PHONE_NUMBER. So it’s pulling that from here. So in our application, automatically this will be set up. Nobody else can see this. This is your personal information, but here I’ve got thatstored in a variable. Pretty cool, right? So let’s go ahead, and let’s create one ofthose clients, right? So we’ll say client equals client, and here’s a little fun fact.If you don’t pass any arguments to the client object on creation, it will look in your environment variables for those Twilio underscore values. So like the Twilio account SID, so environment variables are an excellent way tokeep your keys hidden, and not leave themsitting in the front seat. Check the notes for how to dothat locally on your machine. So now we have an authenticated client that we can use to complete these to-dos.So the first one I think weshould do is tackling that, sending the message, right? That was down here. We’re gonna send this message, I’m gonna come in here, and I’m gonna deletethis keyword called pass. And I’m gonna start withactually, you know what? You got this. Go ahead, and write thecode to send a message. Now don’t worry if youdidn’t memorize the syntax, I’ve put links in the notes to the Twilio docs ready? Pause me and write thecode to send a message using the to, the body,which is come here, right? So we’ve got the twoin the body coming in, and all you need to do is set the from, and you can set that fromyour Twilio number here. If you do it right, and fill out the form, you should get a textto your phone number.You’ve got to text your number. So a couple of gotchas inPython spacing matters. So make sure that you’reindented under the function. See how this is indented here? Make sure you’re there, and remember that from, F-R-O-M, from is a keyword in Python. So it’s from underscore, right? You ready? Go ahead. Write some code to senda message, pause me, and then I’ll show you how I did it. Ready? You got this? Okay. How’d you do? So here’s how I did it. So I use the client, and I use messages create,and I passed in two, and that’s the, what’s comingin from the function there, and the body is also what’s coming in front of the function there, and then I had to use from underscore, and I’m gonna say the TWILIO_PHONE_NUMBER. Awesome. And I’m gonna click theShow in a New Window. Cool, so we’re gonna text my number here.So that’s plus 1-053-461-5537 and we’re gonna compliment me. Person to compliment is Craig, we’re gonna say Craig, Craig, is completing to-dos and we’re gonna send the compliment, and I should get a text. It says that my message wassent successfully, and awesome. I got it, and now I’mgonna remove that to do, I’m gonna feel good. I love removing to-do’s. There’s nothing, nothing better than that.So what do you say we get the next one? Let’s do it, we can do this. Make this return a collection of messages that were sent from the number. Should we do it? Let’s do it. So get sent messages is usedin this index function, right? So that’s what’s pulling out the messages. So let’s take a look againreal quick at that template.Yeah, so it’s saying if messages, if there are any messagesfor message in message, write out the message body. So that’s gonna just loopthrough those messages. So we are going to passthrough the message object, a list of those message objects. So in this GET sent messages, we see that it’s an empty array, so that’s why it’s never showing up. So we want to replace this with a call to get the client call log, right? Do you remember how we did that? Okay, you have the link to the doc. So go ahead, give me a pause, and see if you can’t get it. If you get it, and refresh the page, you should see the message,and recent messages.Ready? Pause me. I’ll show you how I didit after you unpause. You’ve got this. Okay, this is how I did it. So I used client.messages.list, and remember we could be using an account that has multiple numbers. So we really only want to get the messages that were sent from our Twilio number. So again, that’s from with an underscore, and we’ll do TWILIO_PHONE_NUMBER. So that’s a way of querying that, right? So we’re saying we only want messages that were sent to the TWILIO_PHONE_NUMBER, and if I come over here,and refresh, there it is.Craig says, Craig is completing to do’s. See more compliments at HDPcomplimentary.Glitch.me. So yours will be whatever yours is there. Pretty cool, right? Great job getting thatapplication up, and running, because it’s actually running. You could totally share that out now by sending a text messageto someone you trust. Wait, well actually, maybe you can’t. I seem to remembersomething about our accounts being limited verified numbersonly while in trial mode.Now, API limits are probably something that we should look into really quick, since they’re pretty common with every API that you might encounter. Let’s take a quick detour, and explore some limits, and then we’ll get rightback to implementing this app in a full stack JavaScript app. APIs are designed to have limits. As you can imagine, if you were the maintainerof a web based API, you wouldn’t want someonemaking millions of requests in a short period of time.The chances are your API servercouldn’t support the load. The typical solution tothis is the throttle, or limit the number of requests that you can make per second. Typically these limits are introduced when you get your API keys. If you’ll recall on the Twilio console where we got that trial number, we were informed that not only will messageswe send during the trial have that trial textthat we’d been seeing, it also said that we canonly send a verified numbers. What do you say we see what happens if we try? Now, I don’t know about you, but I find that having peoplethat support you in your life to be super important.Now for me, hands down,that person’s my mom. Like no matter what I’m doing, she’s just there in thesidelines cheering me on. Whenever I launch something new, you can pretty much guarantee that she’s helped me test it out. So I’d like you to do this. I’d like you to think ofsomeone like that in your life, and I’d like you to send them a compliment using Complimenter.So I’m gonna add my mom here. So I’m gonna add her number, and that is 1-602-609-5813. So used to just pressingmom on the phone, right? So I’m gonna say my name is Craig, and I’m complimenting mom, and mom is infinitely supportive as you’ll soon see, I’m sure. So obviously you shouldput in your friend, or family or colleague here. Here we go. Alright, so I’m gonnaclick Send compliment, and ooh, no, internal server error, yuck. Let’s go, and look at our logs, and see what happened. So I’ve got a pretty big stack trace here of what happened on add compliment, and if we come down here, it says the number is unverified. Trial accounts cannot sendmessages to unverified numbers. Oh, right, verify. Oh, we can verify themat Twilio.com/verify. Let’s go ahead, and do that.Can I can do that? That’s cool. Go to awesome. So now I need to get mymom’s number in here. I need to get her to beverified so that she can see it. So you can actually do this pretty easily, and what this will allow me to do is to be able to have my trialaccount be able to text her, which is all we need, right? So what I’m gonna dois I’m gonna click Add, and they will call youwith a verification number, or I’m gonna make it text you instead.So what I’m gonna dois I’m going to put in my mom’s number here, put in (602) 609-5813. So what I’ll do now beforeI click the Text Me, is I’ll say, hey mom, I’m texting her this it’s me again. Hey, I’m going to verify your number. You’re gonna get text from Twilio. Can you send it back to me? And she wrote back. Sure thing sweetie, aww. Okay, so now that I know she’s ready, I’ll now send that validation message, and so I’ll click Text Me, and I will wait for my momto tell me what that was, and then she should beable to send me the code.Okay, so she texted me, and that number is 946541, and then I click Submit. Awesome, so now my mom is verified. Here she is. She’s in this verified numbers. Now I can text her nowlet’s go try that again. Let’s get back to thisinternal server error, and I’m gonna refresh. Reload that, and it’s gonna say you’re gonna submit the forming, and that’s totally fine. That’s what I want it to do. It’s actually what I want it to do, and we say continue, and boom, we did it, and my mom should geta message, and she did. She just sent me an emoji heart. I hope you’re now ableto show off your app to your supportive person.It’s really nice to have thatsupport as you’re learning, and building things. If you don’t have someone like this. My mom’s pretty supportive. If you want to just text her, I bet she’ll shoot you backsome words of encouragement. No, of course this appisn’t gonna go viral in this trial mood, but this is a greatprototype of the concept. Most of the time APSwill give you a chance to get your prototype together before they start charging you, but being aware of the limits will help you plan your efforts. Remember to carefully read thelimits, and error messages. Most API will guide you intohow to deal with limitations.Now let’s get started with a JavaScript basedimplementation of Complimenter. Now we’re gonna implement that same Complimenter application, this time using JavaScript. I’ve got a full stack JavaScriptapplication mostly built, and ready for us to tweak. By full stack JavaScript, I mean the server iswritten in JavaScript, and there’s some front end code that’s also written in JavaScript. On the server side, the application uses Node.js, and the web framework express. On the front end I’ve used theclient side framework view. The Python version that we sawearlier was all server side. There is some things toconsider when implementing a client side applicationwhen using an API. So let’s explore those while we get this JavaScriptprototype up, and running. In the notes, I’ve supplied a link to the repo that you can use to createthe new Glitch project. Go ahead, and copy, and paste that. I’m gonna click Clone From GET Repo, and then I’m gonna paste the repo. Alright, so we’re gonnado the Node version. So this is Node, and again, if Glitch takes awhile to spin up, that’s okay.It might eventually show up, or it might Glitch out, and if it does Glitch out like this, like sometimes I mightjust say the assets folder, just go ahead, and do it again, and it’ll eventually work for you. Awesome, here’s mine working. The JavaScript version ofthis project is implemented as a very simple SinglePage Application, or SPA, and what that means is thatonce the page is rendered, the client will responsible forrendering parts of the page. We won’t rely on a fullpage reload from the server to load new pages for us. Let’s take a look at app.JS the server side of our application. So we’re gonna look at app.JS. So let’s see this first .env here. This will load up ourenvironment variables, which we’ll take a lookout here in a second.Then it’s using express, which is a web framework, and you’ll note that it’sexposing static files in a public directory. So this is a single page application, and it’s rendered in publicindex.HTML. Let’s take a look there, Publicindex.HTML. So this here is the view dependency. If you haven’t seenview before, no worries. This is a prettystraightforward way of using it. So what View does is ituses these V dash, right? So it’s these V dash attributes, and those are view specifics.So basically this is saying if the compliments thatlength is greater than zero, and we’ll see how complimentsis defined here in a bit, and as you can see if it does exist, it’s gonna loop througheach one of the compliments, and then it’s gonna write them out. So it’s gonna write them out using that double mustache syntax here. So it’s gonna write out the compliment that’s in this loop. Okay, so that compliments variable is initialized in our application.Let’s scroll down to it. I’ve put the whole applicationin one single file here. So we don’t need to worryabout packaging, or anything. So the way that you create a new view app is by saying new view, and you can see herethere’s this data attribute, and as you’ll see, compliments is initializedas an empty array. You can add instancemethods to your application by adding a methods objectin the view constructor. So we have a method herecalled refresh compliments. Now you might not have seen this before, but if you’ve had a hard time keeping track of promisebased codes in the past, this feature here is the onethat you’ve been waiting for. You’ll see here that the keyword async is before the name of the function. So it says async refresh compliments. Once a function islabeled as asynchronous, you can now cause functionsthat return promises to behave synchronously. Meaning they don’t moveon to the following line until it completes. So this line here makes a fetch, right? So fetch returns a promise, but there’s a keyword hereof oh wait, right before it, and this code will wait forthe fetch call to complete, and then assign the future value of whatever this is into the response.In the same is true here response that JSON returns a promise, and this will wait until this is done. One thing to note isthat this async function makes it so that refreshcompliments now returns a promise. That is it’s return valuewill have a then method that returns this value. Now if that doesn’t make sense just yet, just you await it will. Just try, and let it all async in.A dad joke, double whammy. Sorry, I’m kind of obligated to make all these jokes. Really though, most devs that I talked to find this async await more straightforward to use than promises for code that’s actuallysynchronous in nature. Alright, so what is this code doing? So it’s making a GET request. Fetches default method is a GET to a URL of /API/Compliments. So that’s in our server side code. Let’s flip back to here to app.js, and you define routes withexpress using this app.GET. So whatever the HTTP method name is. So app.GET/API/compliments, that’s what we saw. So when that happens, thisfunction here will run, and we’ll pass in the request, and the response, and here’s our first to do so we want to get the message log. So first before we do that, we better install the TwilioHelper Library using NPM.So I’ll click on Tools, and then I’ll click on this logs, and then I’ll click on Console. Now I’m gonna run NPMinstall, install Twilio, and I’m gonna do –save. What that will do is itwill update a file called Package.JSON after it installs, and this is much like wesaw in the Python library, we did the freeze, this–save will update that file so that the Twilio dependency is there. We’ll let this complete. Awesome, and so now when youmake a change from this side, we always need to say refresh so that we can refresh the project, and see the changes that we made, and so if we look inhere under package .JSON, you can see that there isa dependency of Twilio.Great, so now that wehave things installed, let’s go ahead and updatethe in the .env file. So that’s this key. See this little key.env here? This is gonna allow us toput our information in here. So I’m gonna go ahead, I’m gonna grab my account SID. You should do the same with yours, and grab my Auth Token, and last, but definitelynot least my phone number. Alright, and now we canuse that in our code. Let’s go right above this port. Right below this port here. We’ll make a new Twilio client, and we’ll require, actually that probably looks better up top a little bit more.Let’s move that. Let’s do that right. This is all out ofalphabetical order, isn’t it? Let’s do this right here. Here we go, and thenwe can instantiate one that will look better down here. So I’ll say const clientequals new Twilio client, and again, it’s gonna pullfrom the environment variables of the Twilio underscore, and just to show you how you do that here. So we’ll say const theTWILIO_PHONE_NUMBER. If you ever wanted to pull something elseout of the environment, you use process.env.thething. So the thing was called Twilio, I think it’s called phone number. Let’s double check TWILIO_PHONE_NUMBER and env.TWILIO_PHONE_NUMBER. Yeah, cool, awesome. So let’s get that message log. So what I’m gonna do isI’m gonna replace this. So we’re getting the compliment. So we’re getting sent messages.So this to do get a list of messages sent from a specific number, obviously Twilio number there. So what I’m gonna do is I’m gonna replace this array with my code, and actually you want to give this a spin? Well, one thing to note is that the function is marked async. So you can, and you probably should use the keyword await, right? So this is an async function. So make sure you use the await keyword. Are you ready? Just make the call to the messages API to get a list of messages that were sent to a specific number. Like the to-do says. Don’t worry if youdon’t have it memorized, I put a link to the docs in the notes. Go ahead, and pauseme, and give it a shot. When you unpause me, I’llshow you how I did it. Ready? How’d you do? So what I did was client.messages.list, and in the JavaScriptClient Helper Library, you pass in an object with the parameters.So we say from not a key word here, and we’ll say TWILIO_PHONE_NUMBER, and like I said, we shouldmake this be a wait, because we’re gonnawait for that to happen, and boom, just like that of that to do, well, why don’t we change? Why don’t we take a look, let’s go. I’m gonna change this tobe Complimenter of a mentor that’s not very nice to Complimenter.js. Compliments, I’m gonna closethat, and let’s go ahead, and we’ll do show when we should see themessages come through.Oh, we shouldn’t see themessage come through yet, right? Because we aren’tpassing anything through. We’re passing down these compliments. Alright, let’s see. Let’s see if we can getthis next to do done them. Gather only the body of those messages for sending to the client. Okay, oh right, becausewe don’t want to send down the whole messageobject to the client. So what we want to do, the API is called compliments, right? And we have an array of text messages.So more importantly though, if I were to send down this message, each one of those messages, it contains a bunch of informations that I don’t think we wantto share with everybody. That message has the phone number of the people who sent the message. I should never send information that I want to keepsafe down to the client. So really we only want the body. So let’s see, I have an array, and I want a new arrayof just message bodies.Now to me, this sounds like a great use of the array.map function. So sent messages is an array. We’ll say sent messages.map, and the map function, map takes a function that will receive each value in the array. So that will be a message, and it takes a function, and if it’s on one line, we can skip the return keyword, and just put what we’d like to see.So this compliments array, we want to see the arrayof message.body, right? So what this is saying is like for each of these messages in here, just return the message body, and put it in compliments. Makes sense, and then it’s gonna send down the JSON representation ofthat to our view client. Should we see if it works? Alright, we’ll save this, and now, oh, there we go. It’s working already. So we’ll see.There’s a new one from my mom, and it says, mom says, Craig is so proud of you, sweetie. Oops, it’s nice, it’s sweet. She wrote back, andthat’s what I love about having someone use your applications. It looks like I stillhave some UI work to do to make it more clearabout what’s happening, because my mom wrote so proud of you sweetie in the compliment, and that doesn’t make muchsense, but I feel nice, and again this is using the number, this was not sent from this app. You can see it was sentfrom the Python app, right? This is Complimenter.js, but this is using a different data source, and you know what? While we’re here, why don’t we look at how easy it is to see what the data was that wassent down from the server? So I’m gonna right click, and I’m gonna choose Inspect. I’m gonna click on this Network tab here, and I’m gonna refresh the page, and you’ll see it make that request. So if I click on this Compliments here, you can see here is the message.Here’s that array thatwas sent down, right? You can imagine that if we sentdown all of those messages, we’d have that data very easy to get. So again, this is the developer toolbars if you say View,Developer, Developer Tools, you’ll be able to see this. I’m gonna take a quick break, and then I’m gonna swing right back, and finish up the remaining to do, creating a new compliment. (calming electronic music) We just finished displaying alist of all the compliments, and now it’s time to deal with how they get added on the JavaScript side. So let’s keep the front end code, and see what happens. So that is in publicindex.HTML. So here’s that form. Alright, so we have this it’sa form that goes to post. It goes to /add compliment, and it’s got these V dash models. So here’s like V dash, modeltwo, Videsh model sender, and that’s how view does data binding.So anything in that field willbe bound to that variable, and if we come down to the button here, we will see that thenormal click, it won’t, it will prevent, right? So that prevents it from being submitted, and it calls this send compliment method, which is defined inthe method stanza here, which is this send compliment. Okay, so it goes ahead, and it grabs the stuff from the form so it pulls them all off. They also happen to be the same, it’s in a thing calleddata, then it uses fetch, and it uses it synchronously, right? So it’s got an a wait, it’sgonna wait for fetch to go, and it passes That as JSON, and were saying that it is JSON, and we’re passing JSON up, and we’re doing a post request, and let’s go ahead, andwe’ll take a look in app.js, and we’ll see here that we’reusing this body parts here, so any request that comes inwill automatically get parsed, and the way that that looks is a, so here’s this post, right? So here’s, we failed, we fixed this get, and we got to get rid of these two do’s.Forgot to erase those. Those are to-done. Alright, so it comes in here, and it’s posted to API compliments, again, an async method. So it’s gonna pull off ofthe request body too right? So, and because of the body was parsed, it’s automatically inflated here. So body the two, it’s gonna pull the two off of the field, and request that body sender, or Costa biosphere, very compliment, and it’s using the Bactec so it’s automatically filling those out. So here we are. Here’s our to do. Why don’t we just synchronouslycreate that message? Well, you want to give this to do a try? Go ahead, pause me. I put links in the notes, I’ll await for you to unpause me, and then show me how you did it. How’d it go? Here’s how I did it. So we want it to be synchronous. So I’m gonna go ahead, and use await, and I don’t really need anythingfrom the create a message, so I’m not gonna assign a return value, and I’ll use the fact thatthe parameters are the same.So I’m gonna sayclient.plant.messages.create, and in JavaScript you can do this. If you have a variable named two, it will just set 2:2 from embody, right? So this is just basically, because there is a variable called two, it knows to make a new onecalled two in this array here. Alright, so let’s give that a go. So I will go ahead, and click Show Here, and I’m gonna send another one to my mom. To mom, no, my name’s not mom. Well my name’s Craig, and I’m gonna compliment mom. Her compliment is a really patient tester. Mom is a really patient tester. So here we go. Yep, there it is. So see right away it came back, and you’ll see that the forms cleared. So let’s see how it did that. So back in the index.HTML we have this, we posted it, and it got back the data, and it awaited for the result, and then it wrote out the result, and we saw this information come down. So we could actually, if we wanted to, we could do View,Developer, Develop Tools, and we should see in the console.Here’s the object that got sent back. So it was a success of false. Now, we forgot to update that, didn’t we? I’ll have to look. I thought we looked at that. Now, if you’re gonna say, yeah, that was a successful journey there. Good job. Glad we caught that. Speaking of catching stuff, what happens if things go wrong? So much like before when weneeded to capture the error using the catch method on promises, we need to do something similarin this async await land.So we need to use astandard try catch block. Now if you haven’t seen that before it’s, it’s pretty straightforward. What you do is you say try, and if any error at all is thrown what will happen is itwill call this catch block, and it’s a good way to handle errors. So we’re gonna catch that error. So the error object has a status, and you can send that down to the client by saying response.status,and we can do error.status.We’ll just pass thatstatus straight through, and this is changeable. So we’ll send JSON,might as what happened. So we’ll say success isfalse for real this time, and we’ll also send, why don’t we send the message, we’ll send that error error.message. There we go, and you know what? We can use prettier here too. So we’re gonna clickthis format, this file. Let’s make this thing prettier. Ooh, nice. Okay, so we’re going to try,and if there is a failure, we’re gonna send this back, and then otherwise we’re gonna go ahead, and send down the success of true. So we got to break it somehow. How should we do that? Let’s say instead of from,let’s make this be 42, the meaning of life, and everything. So that is obviously not avalid TWILIO_PHONE_NUMBER. So let’s go ahead, and let’s bring up Complimenter, and I’m just gonna oh, it did refresh.I was gonna refresh it, and it did for me. So we’ll send another message to my mom. My name is Craig to my mom, and the compliment isgood at catching errors. Okay, and I’m gonnaclick Send a Compliment. Let’s see what happens. Oh look, so here we got the error. It’s a 400 that came back, and the from phone number 42 is not valid.CMS capable, or inbound number, or short cover from your accountis a better version of it. Cool, right? And let’s make sure we don’tleave that in that state. So we’ll undo that, and save it, because I want my mom togive me another compliment. Again, we are good to go. Awesome job. You’ve now used an external API in two completelydifferent web frameworks, and paradigms even. you should be sending acompliment to yourself. You’re accomplishing great things. Way to stick with it. One other thing I’d liketo take a quick moment to point out is that theserver code that we wrote, you might’ve noticed it was prefixed with a /API server code that interfaced with a client.Now here’s my question to you. Do you think that the API code that we wrote togethershould be considered RESTful? Why don’t we take a look at our weathered scavenger hunt card? So it’s definitely aClient-Server Architecture. Our client happens to be, in this case, a view applicationrunning in the browser, and our server is a Node.js server, but any client couldconnect, and use this.It’s definitely Stateless, right? We aren’t requiring any priorknowledge about the client. Well, at the moment we aren’t providing any caching informationso we could, right. We could fairly easily pay attention to those headers coming in,and respond appropriately. It would require us writingsome additional code, and thinking through some edge cases, but we could do it. Let’s put this in the maybe column. Yeah, for sure, right. In fact, it’s a little layered already. Our API is calling another API, but our client doesn’t need to know that. We could also addadditional functionality, and the contract wouldn’t change. We haven’t even talked about this one yet, and it’s the only optional requirement. Now basically this meansyour API returns code that is runnable, like maybe it returnsan embeddable widget, or some actual JavaScript code.This doesn’t make senseon our application, and that’s okay. I’m gonna drop this one in the no, so we’re looking good so far, but here comes the doozy. So remember this one hasfour subsections, rut row. Currently we’re just representing all the complements as strings, and absolutely no way to identify them. So we fail this sub requirement, and therefore this thing is a no, but let’s keep goingthrough the rest of these.Pun intended, sorry. We definitely do not allow any sort of manipulation of compliments. So this is another fail. We haven’t gone over this yet, but by using headers wecan tell that this is JSON. The message sent down has a type, and it is clear that it shouldbe JSON decoded to be used, and last, but certainly not least, Hateos, or Hate OS is anoften forgotten about part of the RESTful constraint,and very hard to say.The idea here is thatthere are links provided to show off what moreyou could do with this, and where you couldfind related resources. It provides URIs, or links. We did see this in both theSpotify, and Twilio ones. However, ours doesn’tneed to provide links to other resources. So we don’t have a RESTful API, and that’s okay. It works as is. It does look like we couldget there pretty quickly if we wanted to. One thing I want you togain from that exercise is that you now have theability to identify whether, or not an API is RESTful, and I hope that felt pretty good.We’ve now completed that scavenger hunt. We revealed all the constraints, and I hope that most ofthose are pretty clear. Please don’t feel like youneed to memorize those. You can find these same constraints littered all over the internet as a prize for finishing theconstraint scavenger hunt, I’ve dropped links to my favorite REST API constraintdocumentation for you to lean on. I’ve also included links topopular REST API frameworks that will help you design RESTful APIs. Make sure to check the notes. You did it. You just completed a whirlwindintroduction to APIs, and I hope you see how much power they can add to your programming journey by looking at interfaces in general.I hope you’re morecomfortable with the idea of not fully understandingexactly how something is working, but still leaning on that abstraction to build your tools, and applications. We do this all the time withphysical object interfaces, and APIs, or Application Programming Interfaces aren’t all that different. I hope you enjoyed taking this course. I know I had a ton of fun making it. If you think someone you know might benefit from thiscourse, share it with them. I’d love to hear your feelings, your thoughts, and your dreams. So I threw together a little something using a smattering of API’sto capture your feedback.If you’ve got the time, I’d love to have you answera quick text based survey. Text feedback to 1-503-461-5537. Actually, you know what? If you want to, you can also just call, and leave me a message too. I used an API for that too. Please, please, please keepme posted on your journey, and really I can’t waitto see what you build. Thanks for hanging out. (calming electronic music).

As found on YouTube

Get Your Free Helium Miner Here – Join Now

briansavic@me.com
 

Click Here to Leave a Comment Below 0 comments

Leave a Reply: