- Sloth Bytes
- Posts
- š¦„ Understanding APIs
š¦„ Understanding APIs
Hello friends!
Another week, another Sloth Bytes.
Seems that a majority wanted to keep weekly challenges/projects, so Iāll keep them.
If you have any other suggestions let me know by replying!
Sloths Can Turn Green
Sloths can grow a layer of algae as a camouflage method to help protect them from predators and gives sloths extra nutrients through their skin.
APIs
An API stands for Application Programming Interface.
Good to know I guess? Everyone just calls it an API.
This week weāll keep it simple by covering the basics, but later on Iāll dive deeper since these can get pretty complicated.
What is an API?
APIs are like the middlemen of the digital world, they allow the front end (what users interact with) and the back end (where data processes happen) to communicate effectively.
A Cooking Analogy
Think of an API as a waiter in a restaurant.
The kitchen is the back end where your food is prepared, and the dining area is the front end where you sit and order.
The waiter (API) takes your order to the kitchen and brings back your food.
In programming, APIs take user requests from the front end, fetch the required data or action from the back end, and deliver the results back to the front end.
Why are APIs important?
Simplicity: APIs allow front-end developers to not worry about the database or server-side details. They simply send requests and handle responses.
Efficiency: Data fetching and management are handled more efficiently. Since APIs can communicate seamlessly between the server (back end) and the client (front end), it makes applications faster and more responsive.
Flexibility: Developers can quickly implement features that rely on external services (like social media logins, maps, or payment systems) without starting from scratch. This is why a lot of services offer ādeveloper APIs.ā Makes it really easy to add their service to our own application.
Example: Getting a random emoji from an API
Letās do an easy example of how APIs work.
Hereās a simple fetch to get a random emoji from a free API (in JavaScript of course)
//Extra tip: It's usually common to name the fetch either "response" or "res" (short for response) :)
const response = await fetch("https://emojihub.yurace.pro/api/random")
const emoji = await response.json();
console.log(emoji)
This will give us information about a random emoji.
Wanna try it out?
Copy that code snippet and open up the developer tools console.
How I do that Iām a little dumb
Mac | Windows |
Command + Option + J | Control + Shift + J |
or
right click
Click inspect or inspect element
Go to the console
Once youāre in the console, paste that code snippet š
or you knowā¦ paste it into the IDE, thatās cool too.
Hereās an example of the information youād get from it:
{
"name": "oncoming fist, type-6",
"category": "smileys and people",
"group": "body",
"htmlCode": [
"š",
"šæ"
],
"unicode": [
"U+1F44A",
"U+1F3FF"
]
}
Now you can use that information for your own application!
Alright cool, why should I care about this?
Essential Tools: APIs are crucial for making different software systems work together. Basically every company relies on them heavily.
Boost Your Career: Knowing how to use APIs is a must-have skill if you want to be a web/mobile developer.
In Summary: APIs are the middlemen that communicate between the front end and back end which makes development easier.
Show me you can use an API
Use this repo and pick any API youād like and create something with it.
Could be something beginner or advanced, have fun with it.
Examples to get started
Weather app (classic) Example API for it
Cat Fact Generator Example API for it
Gif generator Example API for it
How To Submit Answers
Reply with this:
A link to your solution (github, personal blog, portfolio, etc)
A link to your post on Twitter, Linkedin, or any social platform you use.
Just released another videoš
Just finished and released another video
Pretty much just me yapping about stuff, so the usual.
Check it out here:
If you subscribed to Sloth Bytes because of that video then uhhhh watch it again.
Besides that, Iām probably gonna start working on another coding project, weāll see if that becomes a video too.
But thatās all from me!
Have a great week, be safe, make good choices, and have fun coding.
See you all next week.
Reply