In this guide, we will show you everything you need to know about how to access an api, so keep reading!
Below you can find out 5 different methods to access an api,
- Method 1 – Using A Public Api For Beginners
- Method 2 – Apis For Beginners – How To Use An Api (Full Course
- Method 3 – Learn Fetch Api In 6 Minutes
- Method 4 – What Is An Api And How Does It Work? (In Plain English)
- Method 5 – Working With Apis In Python – Code In 10 Minutes
Method 1 – Using A Public Api For Beginners
Whats going on guys my name is j and in this video i want to show you how you can. Use a public api so for this video were gonna be using open weather map dot org they have a. Very very simple api they have a ton of data that we can use so if you go there and. Then you click api you will see all these options right here but the one that i want is this.
One the first one the current and weather data thats the one that i want ok so click subscribe you. Will see all these options on the one that were going to use is the free version which is gonna. Work for this video any words for like a personal website and stuff like that so click on the get. Api key and start so you need to sign up just like a normal website does your email and password. And all that stuff and theyre gonna give you an api key so that way you can request all that.
Data so lets test the api so lets see if it works i have here the url that they provide. Which is this one right here alright so now we need to add question mark q equals to whatever cd. And you can see that i have it already there so i live in orlando so its orlando and then. And ab have id equals to whatever api key they gave you all right so thats mine dont try to. Use mine because its not gonna work for you im gonna hit enter and here you go so i have.
All the data from the current weather in orlando which is great one thing that i want to do right. Now is because if you can see here on temperature thats a is a different unit we use a different. Unit so im just gonna put it right here after this and so its gonna be unit equals to imperial. And then and im gonna leave the app id so im gonna hit enter again and now we have whatever. You use you can change it but this is what we use in the united states cool now that we.
Have this url ready to go im just gonna go to my text editor and start coding here i have. An html file the only thing i have is requesting jquery whos gonna were gonna use it to request the. Data we have a script gis which is empty and we have a style dot css is empty were gonna. Add some stuff in a minute so lets start by adding some html here so the first thing im gonna. Do im gonna add our container everythings gonna be inside that container so it can be like whether container okay.
And inside there we can do a paragraph and then we can add like a class off this can be. Actually you know what first im gonna add an icon like if its raining if its raining we can do. Like a rain cloud with some drops or whatever if its sunny we can add you know a sun or. Something like that so thats the icon will just put icon as a class this is gonna be like the. Name so if its raining is gonna be like rain if youre sunny is gonna be sunny so this is.
Have jquery we can use something called get json and get json is going to get all these data for. Us because this is jason this is json file so lets go back there and lets do im dollar sign. Dot get json just like this and then were gonna do inside here were gonna do the url coma and. Then function sorry function just like that alright so we need to include that url here lets go back and. Get it where is it here is copy pasted right there alright so what im gonna do im gonna put.
Here inside the function im gonna put data all the data is gonna be inside there song i can do. Something like console log data so im gonna save that and lets go back here so this is my page. Right now im gonna reload my page and here you go we can see all the data the same thing. We have here we can see it we have it now available for us on the website everything is here. Alright cool now that thats working lets go back and here inside the function were gonna do like lets create.
The variable of the icon so lets do variable icon and i have a url that they provided for everyone. To get the icon so if we go here lets see if they have here on whether so you can. See that there is a icon here and there is like a number in a letter you dont understand how. Were gonna use this in a minute so they provided a url for that icon so lets see lets open. Here and lets go back and what was the code is what 11 d lets copy and paste it dot.
Png look at this so every single thing is a different thing depending on the weather the icon is going. To change and its gonna be this url cool so lets go back to my code lets do whoops thats. Not what i want i want the url which is this and then im gonna do plus and we need. To add that code which is gonna be data dot and lets go here lets see so hes data dot. Weather zero and then dot icon so these data dot weather zero and this is because its an array its.
A list you can see that we have oops quit we have zero one and its an array so we. Need to do square bracket zero and then dot icon thats it now were gonna have if we call icon. Were gonna have this and then whatever code it is and actually i need to add the png file so. The png format so lets go plus sign and dot png now thats gonna work there you go so now. Let me call the icon and see if it works also the log icon alright lets go back lets reload.
This page here it is just click on it and thats it we have the icon alright so lets go. Back here so thats working lets remove console.log we dont need it and now what im gonna do is i. Want to add that icon inside this image so lets do dollar sign we can that that the icon class. And then were gonna do attribute and then attribute is gonna be this source and that source inside that source. Is gonna be the icon which is hold this all right cool lets save it lets see that works lets.
Reload the page yay we have here it seems like its like thunderstorms or something really bad whats going on. In here which is true like todays a very rainy day so yes all right cool so we have the. Icon done so lets do the same thing with the temperature so lets create another variable lets call it temp. Equals two and its gonna be data dot i think is weather dot ten yeah i think thats thats what. It is and this is gonna give us that number so lets go back make sure make sure that thats.
True all right um no actually its main so i have to fix that so we see main dot temp. So lets go back its not whether is main all right cool now we do the same thing were gonna. Go here and this is the dot the class temp but this time were going to append that data and. This was gonna be time lets save that and lets see what happened thats it here we go we have. We have the temperature we have the icon the temperature and i think were missing our weather text like its.
Raining or its not raining sunny what what it is so lets go back and lets do that lets do. It right here in the middle that way we are like organized so variable we can create something called weather. Or weather name or i dont know whatever you want equals to data dot weather lets go back and see. Where it is so weather and then theres the rays im gonna get the first one and its gonna be. Thunderstorm okay so there is thunderstorms so weather 0 dot maine then were gonna go down here and want to.
Do the same thing were gonna get the weather dot append this appended data and its gonna be what lets. Save it lets see what happens if it if it works yeah there we go we have the cloud it. Says that we have a thunderstorm and is 86 now i dont want to show this point for nine and. Point 49 i just want to show 86 and there is a trick we can do it right here on. The weather no actually the temperature sorry we can do math dot floor and lets see if the helps oops.
Sorry is math like this lets go cool now we have only 86 all right so you dont have to. Do the math floor actually theres some other options so im gonna put a link in the description if you. Want to play with this but i think thats it we just need to kind of make it later prettier. Because right now it looks very very weird so lets go and lets add some css so lets say um. Weather container lets do like a i dont know like a gray background lets you know what lets just align.
Everything to the center and we have the weather text the one that sets thunderstorm right now lets do font. Size im like twenty two pixels you know bigger and lets remove all the margin because i know a paragraph. Have like margin we have a temp like the temperature we can do this one i wanted like pretty big. So lets do like sixty pixels same thing margin zero and whoops and the font weight i want it to. Be bold alright lets save that i think thats thats good for now lets reload the page and here it.
Is so you have the icon it said we have chunder storm and its 86 so lets see what happens. If we change like orlando to like new york for example lets go in there lets go here lets say. You know what lets do something real quick right here so we can do that very easily so lets draw. A variable called cd for example and right now is orlando and right now in the url what we can. Do is lets remove the name orlando we just closed the url there we do plus sign cd plus sign.
And then we open the url again alright so now this is coming from this variable okay so lets save. It lets see if it works yep same thing so now lets change these to like new york go there. Reload the page here is so new york right now 75 clear seems like its a beautiful day so thats. How you do it you can go very very complex and and use another api that gets the usual specific. User locations and then the city variable will change depending on the location of the person and all that stuff.
It can get very complicated but this is a very very simple way to get started and understand how public. Api works not only whether but there is a bunch of other apis with other data that you can use. In and you can just use you can use it just like this okay so thats it subscribe if you. Want to keep learning and click on the bell icon to receive notifications every time i upload a new video. Thank you so much for watching half a beautiful day bye bye.
Method 2 – Apis For Beginners – How To Use An Api (Full Course
Hello im craig and im a developer in this course were gonna be exploring a term that youve probably heard. Quite a bit that term is api or application programming interface in addition to being able to recite what it. Stands for when you complete this course youll be able to discuss what an api does youll understand why they. Exist and youll be able to list the many benefits that they provide youll even get some hands-on experience using.
A few popular web apis which will give you a taste of what all this excitement is about well be. Starting from the very beginning so there really isnt too much im gonna be expecting you to know before starting. This course i would like to request that you have a touch of experience with coding and a wee bit. Of knowledge about the web if youve written any program at all even the typical first program you know the. One where you write the words hello world if youve done that in any programming language youll be pretty much.
Ready for this course itll be helpful for you to have a basic understanding of how the web works with. Web servers and browsers but dont sweat it well touch on this too now if you havent yet met these. Requirements please check the notes attached to this video for where to get started with 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 discussed are attached to this video ill also drop more information in that section to keep you.
Updated on what might have changed from the time i recorded this now ill do my best to remind you. To look in there when theres something that i think you just have to see but you really should get. In a habit of checking that area out there will be tons of juicy information there now these videos have. Captions so if you feel like you might benefit from having those on please use them this space is all. Yours if you want me to speak slower use the speed controls this you dont and if you and im.
Taking too long of a time just 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 needed me to repeat myself use. The video controls to rewind me if you feel like you need a break to let something sink in by. All means please pause me ill be right here waiting for you i know that ive gotten into some bad. Video viewing habits with all the streaming media now well binging might be a great way to consume an entire.
Season of your favorite show its not the best way to learn something new education isnt meant to be benched. And because of this probably reminds you quite a bit to take breaks and encourage you to let what you. Just learned marinate all right lets get to it api those three little letters generate quite the buzz dont they. Now first id like to take 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 youll start to see its importance and.
Begin to understand why this term keeps popping up in your life after we get a good grasp on the. What and the why of apis well go and learn how to explore two existing ones well get familiar with. A handy tool postman which provides a nice way to interact with web-based apis well use that tool to hit. An external web api to send actual text messages and well get some interesting data back from a streaming music. Service api after some practice using the apis well insert them into a web application the application were going to.
Be covering that specifically there are many great courses available that show the creation thought process and ive linked to. Some of my favs in the notes attached to this video in my opinion the best way to start learning. About any acronym is to focus on each individual letter for api i think we should start on the last. Character the ieee interface lets talk a bit about interfaces that youve seen already interfaces are all around us for. Instance this radio here it has a familiar interface the interface allows me to do things 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 interface allows me to control the way it works through the options that are exposed the. Magic that is happening is completely abstracted away from me and im still in control of what has determined that. I 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 new features like changing the time and setting the alarm i.
Still have no idea how this works 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 the new versions of the interface. Still extracting away things for us but enabling us to be in control of the new features sometimes these physical. Interfaces get so recognizable that they even make their way into gu eyes did you hear that there it is. Again gui or gui graphical user interface this is my streaming music app on my phone and theres my familiar.
Play button in the user interface or you i and i know what that play button does when i press. It but i have no idea how it does it and im okay with that level of abstraction i depend. On it either what would i do in public transit without music i can talk to people hi hows it. Going now the developer who wrote this streaming music application of course understands how the play button works she coded. The button so that when it gets clicked the music starts playing heres the thing though our developer is also.
Working with quite a few interfaces that 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 an event handler on the button what. She didnt have to do however was write the code that makes the button interact and change with the press. She didnt 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 thats available from the application. Framework that was used to create the app because most apps need buttons this interface has been created to help. Our developer or application programmer to use now by implementing the button interface our developer was able to make her. Code run when the button was clicked its worth noting that the code probably also uses a media player api. Thats provided by the rating system of the device like android or ios this media player api abstracts away needing.
To understand the details of how to send audio data to the hardware the developer knows that they just want. To call the play method of the media player api i suppose to the song isnt stored on the device. Its being streamed over the network so a web-based api call has been made over the internet to get the. Data its actually apis all the way down to the ones and zeros providing abstractions at many levels lets 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 be physical or software and as a user of the interface we dont need. To understand the implementation we dont need to know how it works we just need to know what weve been. Allowed to change or see interfaces abstract away the implementation now well the ui or user interface is made for. The user of the application the api is made for the application programmer to use and extend in their applications. With the i covered in our api lets take a deeper look at the rest of the api acronym an.
Api is a contract of sorts it defines how its expected to be used and it defines what you can. Expect to receive by using it think of it as a set of tools designed for software developers like yourself. An api is created to help make your life easier by giving you access to data and by providing you. With an abstraction of the implementation you know not needing know how its doing whatever its doing they save you. From needing to create everything yourself when designed well they make doing nearly impossible things happen in just a few.
Lines of code youre probably starting to see why its important to get familiar with them right i want to. Do a quick word of warning here about some naming issues that youll probably run into these days the term. Api is almost always used as a way to explain web-based apis in fact its probably safe to assume that. When you hear api in the wild its most likely that people are talking about a web-based api now well. Explore those here in a few however if we focus on all types of api instead of just the web-based.
Subset well get a better look into why web-based apis are so popular so hang tight were getting there ap. Ice are everywhere in your software journey just about everywhere you look your programming language whichever one it might be. Provides many apis lets take a look at one thats common in all of them they all provide some way. Of working with strings you know like a series of characters you want to make your text all uppercase just. Call the api method and voila you could probably create that uppercase string all by yourself by doing some sort.
Of low-level bit math on each character but you dont need to because your programming language has abstract adad away. For you and provided a handy string api it exists because this is a common enough problem that developers run. Into because these programming language specifications are just interfaces different operating systems can supply their own implementations so that the. Code works properly in their environment i think an easy way of picturing this is to think about how different. Operating systems like windows or mac os maintain their files theyre totally different yet your programming language provides a single.
Api for working with the file system you can write one script and it works in either mac or windows. Its the implementation that takes care of all the details for you pretty cool right definitely something to be thankful. For it makes our life so much easier not having to worry about what operating system is being used the. Importance of an api to a language cannot be understated theres been some fascinating legal cases where its been questioned. If the language api itself again not the implementation can be copyrighted check out the notes for more on that.
Along similar lines there are different web browsers you know like google chrome microsoft edge safari firefox and brave now. You might not have pondered this before but isnt it amazing that you can write code for the web and. It will work in any of them now this works because theres a set of web apis that web browsers. All must implement in order to make that magic happen for you were standing on the shoulders of giants folks. We really should thank those giants more often there are authors and maintainer zuv libraries that package up code and.
Solve common problems so that you dont need to do it yourself like for instance do you know how to. Programmatically make a photo black and white me neither but i can download and import an image packaged into my. Application and suddenly i can i just call a method and boom i wish real life skills work this way. Id import dancing so i could be more fun at weddings cha-cha-cha frameworks provide an api that allow you to. Extend what has been provided to make it your own like for example most web frameworks provide you with the.
Ability to add a new route to your web application it allows you to write out dynamic data to a. Template that you specify and you do all of this with just a handful of lines of code you dont. Need to understand how its doing things but you do need to know how to write an implementation to what. The framework is expecting in this case youre using the api the contract to write a valid implementation that meets. The requirements and all these api is that we just talked about theyre local to our codebase they exist within.
Our code we use them to avoid recreating the wheel that is to say they assist us in accomplishing tasks. That we need to perform by abstracting away a ton of work for us the stuff that we developers shouldnt. Be worrying about we should be focusing on the business problem at hand and that means a big part of. Your job is figuring out how to leverage these apis to your advantage now i think its an excellent time. To take a quick break i just gave you a lot to think about and id like you to take.
A minute to breathe why dont you jot down some apis that youve used today even if you werent coding. I know that youve seen some in action if youre having a hard time thinking of some ill give you. A hint youre watching a video right now inside of a web browser when a return will explore the concept. Of remote apis ones that arent executing locally in our code base and why thats such a powerful concept it. Took me a while to find this remote control it was in the couch its always in the couch anywho.
This remote has an interface on it right theres the power button and theres a channel changer and when i. Press the volume button it sends my request to my device and the volume changes as if i turn the. Volume up using the interface on the device itself and we know why thats important i want to remotely control. My device and i 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 for instance has a remote api.
You can send commands to it and it responds it even sends back sensor information these traffic signs can change. Based on an api call this drone here is actually remote controlled by an app on my phone see its. Not just physical objects that benefit from remote apis oftentimes we dont have space on our local machines for all. The data thats available like for example have you ever used one of those apps that helps you figure out. What song is playing you send up a snippet of a song you heard playing at a grocery store using.
Your microphone and it sends back exactly what the song is its usually phil collins turns out both grocery stores. And yours truly loves phil collins you dont have room for all the songs in the world on your phone. And with this remote api you dont need to have all of them it does all the searching and processing. And its surprisingly quick how can it possibly do that i dont know but i love the interface its so. Fast oh theres another benefit of remote apis computational power because an api removes the limitations of your local machine.
You can gain access to seemingly infinite amounts of power a good example of that is the ar app of. Google translate you can use the camera on your phone in a near real-time its able to translate directly to. Your screen like instantaneously its using a ton of processing power to make this magic happen and that processing is. Happening elsewhere in la nube it took quite a bit of experimentation in some evolution of ideas but over time. We finally turn this remote api dream into a reality now im going to drop some history and the teach.
But i just want you to know that the struggle to achieve this concept of remote apis was very real. Now most of the problem was that there wasnt a standard that everyone loved things were pretty clunky for a. While as the ideas were sussed out but then it happened a new architectural style appeared 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 im talking.
About here is rest or representational state tra.
Conclusion – How To Access An Api
Thank you for visiting Softwarediscover.com and reading this article! If you found this article useful, feel free to share it with your friends and help spread knowledge.