Logo
Logo
Home
Archive
AI Agent Notes
Advertise
YouTube
Login
Sign Up
Logo
  • Home
  • Posts
  • 🦥 Understanding APIs

🦥 Understanding APIs

May 28, 2024

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

Giphy

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?

An API is an interface or contract that one piece of software exposes so another piece of software can interact with it. That can be a web service over HTTP, a library’s functions/classes, an operating-system API, a database driver, a browser API like localStorage, and plenty more.

A Cooking Analogy

For a web API, the restaurant waiter analogy is pretty useful.

The kitchen is a service with capabilities/data, and your application is the customer asking for something.

The menu defines what you’re allowed to request—the API contract. The waiter carries a valid request to the kitchen and brings the result back.

In an HTTP API, that might mean your browser/mobile app/server sends a request such as GET /users/123, and another service responds with data plus an HTTP status code. But remember: not every API is HTTP and not every API sits between a frontend and backend.

Why are APIs important?

  • Abstraction: Callers can use a capability without knowing every implementation detail behind it.

  • Contracts: APIs define supported operations, inputs, outputs, errors, and compatibility expectations between components.

  • Reuse and integration: You can build on maps, payments, authentication, cloud storage, operating-system features, libraries, and other systems instead of implementing every capability yourself.

  • Independence: A stable API can let implementation details change behind the interface without forcing every caller to change at the same time.

An API does not automatically make software faster. Network APIs add latency and failure modes; the value is a clear, reusable boundary between systems.

Example: Getting a random emoji from an API

Let’s do an easy example of how APIs work.

Here’s a simple HTTP request using JavaScript’s fetch():

async function getRandomEmoji() {
  const response = await fetch("https://emojihub.yurace.pro/api/random");

  // fetch() only rejects for some network-level failures.
  // A 404 or 500 is still an HTTP response, so check the status.
  if (!response.ok) {
    throw new Error(`Emoji API returned HTTP ${response.status}`);
  }

  return response.json();
}

try {
  const emoji = await getRandomEmoji();
  console.log(emoji);
} catch (error) {
  console.error("Could not load an emoji:", error);
}

If the request succeeds and the response contains valid JSON, you’ll get an object describing a random emoji. In a real app you’d also think about timeouts/cancellation, authentication, rate limits, retries, schema validation, and what the UI should do when the service is unavailable.

Wanna try it out?

You can try the snippet in a small HTML/JavaScript project, a browser console you opened yourself, or a Node environment where fetch is available. Only paste code into DevTools that you understand—random websites sometimes try to trick people into pasting malicious “fixes” there.

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 your own test environment, run the snippet and inspect both the returned data and any HTTP/error behavior.

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?

  1. APIs are everywhere: web/mobile apps, libraries, cloud platforms, browsers, operating systems, databases, payment providers, and developer tools all expose interfaces you’ll use.

  2. Contracts are a core engineering skill: learning how to read API docs, validate inputs/outputs, handle errors, authenticate, version integrations, and respect limits matters far more than memorizing one specific endpoint.

In summary: an API is a contract/interface between software components. HTTP web APIs are one very common version of that idea, but the concept is much broader than “frontend talks to backend.”

If you want to keep learning

  • What is an SDK? — APIs give you an interface; SDKs package the tools around it.

  • What is a Webhook? — the server calling you back instead of you constantly asking, “anything yet?”

  • GraphQL explained — a different way for clients to ask APIs for exactly the data they need.

  • Managing server state in React — fetching data is the easy part; caching, retries, loading states, and keeping it fresh are where things get spicy.

Angular v18 is now available! (12 minute read)

Today we are excited to share the next milestone in the evolution of Angular! Over the past three releases we’ve introduced a lot of new…

Vercel Ship 2024 recap (6 minute read)

Vercel Ship 2024 highlighted the integrations, ecosystem, and teams building the web's best products. Read the recap to catch up on all our announcements.

Microsoft Build 2024: everything announced (8 minute read)

Finally, Teams is adding custom emoji.

Mistral AI and Harvey Partnership (1 minute read)

Harvey builds custom LLMs for elite law firms to tackle the most complex legal challenges across every practice area, jurisdiction and legal system in the world.

KREA

KREA – Generative AI made easy. Generate and enhance images and videos using powerful AI for free.

Mediocre Engineer’s guide to HTTPS (13 minute read)

As a mediocre engineer, I took Internet and HTTPS communication for granted and never dove any deeper. Today we’re improving as engineers and learning a rough overview of how internet communication works, specifically focusing on HTTP and TLS.

Best Practices For Naming Design Tokens, Components And Variables — Smashing Magazine (6 minute read)

How can we get better at naming? This post is dedicated to naming conventions, tips, and real-world examples that help you name things in a robust and flexible way.

9 Types of Software Development in 2024 (6 minute read)

Whether you’re aspiring to become a developer or simply curious about the field, understanding the types of software development is fundamental.

Essential ES6 JavaScript Features Every JavaScript Developer Should Know (3 minute read)

As a developer, it's crucial to stay updated with recent technologies to remain relevant and...

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.

GitHub - public-apis/public-apis: A collective list of free APIs

A collective list of free APIs. Contribute to public-apis/public-apis development by creating an account on GitHub.

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.

Keep Reading

Read all
arrow-right
envelope-simple

Join 50k+ developers and become a better programmer and stay up to date in just 5 minutes.

© 2026 Sloth Bytes.
beehiivPowered by beehiiv