Slide 1
-----------
Part 1: Let's dive into APIs, their theory and options to create them!
Slide 2
-----------
Part 1: An API, or Application Programming Interface, is a set of rules letting one program ask another for data or actions—like a waiter taking your order to the kitchen.
Part 2: Imagine using a blogging app to see “travel” posts or add a new one as an admin. APIs make this smooth connection possible by letting the app’s front end talk to the server behind the scenes.
Part 3: If you decide to create a Windows or Mac application to handle your blog posts, that application can use the same API to manage them! You can also open your API for others to develop their applications.
Part 4: You application can use multiple private or public APIs. For example, you book a flight, check the weather, or “like” a post—APIs are working silently to fetch and send data, powering the apps you love. Or you can just grab that random cat pic!
Part 5: Some think APIs are the app itself. Nope! They’re the rules and tools that let software communicate, not the buttons you click.
Part 6: In our blog app, the front end asks the API for a list of posts tagged “travel,” and the server responds with the data.
Slide 3
-----------
Part 1: Check out how easy is to call an API service from your browser.
Part 2: In the browser, you can use the fetch function to obtain data from API. Later, we explain the difference between different API calls, such as GET, POST, UPDATE or DELETE calls.
Part 3: Once you receive a response, you can simply call the "JSON" function to turn it into the JSON object.
Part 4: The fetch function is understandably asynchronous; thus, we have to use promises or async await calls to read the value from API.
Slide 4
-----------
Part 1: APIs follow a simple flow: request, processing, response. Let’s see it with our blogging app.
Part 2: The app sends GET request to ask for filtered posts.
Part 3: The server queries its database, finding all posts tagged “travel.”
Part 4: It returns JSON for the app to show.
Slide 5
-----------
Part 1: What types of API protocols are out there?
Part 2: The foundation of most API protocols is REST technology. Our app uses REST with simple HTTP methods like GET and POST, returning JSON. We will cover REST in the next section.
Part 3: GraphQL is built on top of REST, and lets you ask for specific data, like titles or blog tags, in one request. The GraphQL offloads data management to the client, which is not preferrable.
Part 4: SOAP uses XML for strict, secure exchanges—think banks, not blogs.
Part 5: Webhooks push updates, like notifying a feed when a post is added.
Part 6: Sockets allow for two way, real-time communication, aimed at real time communication such as chat apps.
Part 7: RPC stands for Remote Procedure Call, and gRPC APIs were originated by Google. In gRPC architectures, a client can call on a server as if it were a local object, which makes it easier for distributed applications and systems to communicate with one another.
Slide 6
-----------
Part 1: Try it yourself. Let’s test a real API! Open your terminal and run these commands.
Part 2: This command gets a random dad joke as text.
Part 3: The accept header is set to plain text, so the output will be just a joke.
Part 4: This command gets a random dad joke in json format.
Part 5: The accept header is set to json, so the output will contain extra information
Below is an expanded version of your lecture on APIs, tailored to the
instructions provided. It’s structured as a Lecture (not slides, so no
narrations are included) and designed for first-year university students. The
lecture builds on a single example—a blogging application—while keeping
explanations clear, engaging, and professional. I’ve gone deep into the topic,
avoided surface-level explanations, and incorporated relatable scenarios,
misconceptions, and step-by-step expansions of the example.
--------------------------------------------------------------------------------
LECTURE: UNDERSTANDING APIS – THE DIGITAL GLUE OF MODERN APPLICATIONS
MOTIVATION: WHY APIS MATTER
Imagine you’re scrolling through a blogging app on your phone. You tap a button
to see all posts tagged “travel,” and instantly, a list appears. Then, as an
admin, you add a new post about your latest trip, and it’s live for everyone to
see. How does this magic happen so smoothly? The answer is APIs—Application
Programming Interfaces. APIs are like the friendly waiters at a restaurant,
taking your order (a request) to the kitchen (the server) and bringing back your
food (the data). Without them, apps wouldn’t talk to each other, and our digital
world would grind to a halt.
In today’s interconnected world, APIs are everywhere—when you book a flight,
check the weather, or even “like” a post on social media. They’re essential to
this course because they’re the backbone of modern web development. By the end
of this lecture, you’ll see how APIs connect the blogging app’s front end (what
you see) to its back end (where the data lives), solving real problems like
displaying posts or saving new ones. Let’s dive in with a question: Have you
ever thought the “Save” button on an app just magically stores your work?
Spoiler: It’s not magic—it’s an API at work!
BUSTING A MISCONCEPTION
Many students think an API is just a fancy button or a webpage. Nope! It’s a set
of rules and tools that lets software talk to other software. Think of it as a
translator, not the app itself. This might surprise you—APIs don’t have a “face”
you see; they work behind the scenes.
--------------------------------------------------------------------------------
SECTION 1: WHAT EXACTLY IS AN API?
An Application Programming Interface (API) is a set of protocols and tools that
lets one piece of software ask another for something—data, actions, anything!
Picture our blogging app: When you, the user, want to see all “travel” posts,
the app’s front end (the screen) asks the back end (the server) for that list.
The API is the middleman making that conversation happen.
Let’s start simple with our blogging app example:
* Scenario: You open the app and see a homepage with the latest posts.
* What’s Happening: The app sends a request to an API endpoint (a specific URL,
like https://myblog.com/api/posts), and the server responds with a list of
posts in a format like JSON.
Here’s what that might look like:
* Request: “Hey, API, give me the latest posts!”
* Response: { "posts": [{"title": "My Trip to Paris", "tag": "travel"}] }
APIs use standard web protocols like HTTP (the same thing that loads webpages),
so they’re everywhere. But don’t be fooled—some students think APIs are only for
big companies. Truth is, even small apps (like ours) rely on them!
HANDS-ON WITH APIS – TESTING IT OUT
Let’s try a real API! Open your terminal and test the “Dad Joke” API:
* Command: curl -H "Accept: text/plain" https://icanhazdadjoke.com/
* Result: A plain-text joke like: “Why don’t skeletons fight each other? They
don’t have the guts.”
* Now Try: curl -H "Accept: application/json" https://icanhazdadjoke.com/
* Result: A JSON response with the joke, ID, and status.
This shows how APIs adapt to what you ask for—plain text or structured JSON. In
our blogging app, we’d use JSON to easily display post data on the screen.
--------------------------------------------------------------------------------
SECTION 2: HOW APIS WORK – STEP BY STEP
Let’s break this down using our blogging app. APIs follow a clear process, and
we’ll expand our example as we go.
THE PROCESS
1. Client Request: The client (your app or browser) sends a request to an API
endpoint. For example, to see posts tagged “travel,” the request might be:
* GET https://myblog.com/api/posts?tag=travel
* Here, GET means “fetch data,” and ?tag=travel filters the results.
2. Server Processing: The server gets this request, checks its database, and
gathers all posts with the “travel” tag.
3. Response: The server sends back a response, usually in JSON (a lightweight
data format). It might look like:
{
"posts": [
{"id": 1, "title": "My Trip to Paris", "tag": "travel", "date": "2025-03-01"},
{"id": 2, "title": "Hiking in Japan", "tag": "travel", "date": "2025-03-15"}
]
}
EXPANDING THE EXAMPLE
Now, let’s say you’re the admin adding a new post:
* Request: POST https://myblog.com/api/posts
* You send data like: {"title": "Beach Day!", "tag": "travel", "content":
"Loved the sun!"}
* Server: Saves it to the database and assigns an ID (e.g., 3).
* Response: {"id": 3, "status": "Post created"}
See the pattern? The API handles both fetching (GET) and creating (POST) data.
It’s versatile!
A SURPRISE TWIST
You might think the app does all this work itself. Wrong! The front end just
asks; the API and server do the heavy lifting. This separation makes apps faster
and easier to update.
--------------------------------------------------------------------------------
SECTION 3: TYPES OF APIS – EXPLORING THE OPTIONS
APIs come in different flavors, and each has a role in our blogging app. Let’s
dive deeper.
REST APIS
* What: REST (Representational State Transfer) uses HTTP methods like GET,
POST, PUT, and DELETE.
* Example: Our GET /api/posts?tag=travel is a REST request. To edit a post,
we’d use:
* PUT https://myblog.com/api/posts/1 with {"title": "Updated Paris Trip"}.
* Advantages: Simple, widely used, returns JSON (easy to read).
* Disadvantages: Can require multiple requests for complex data.
GRAPHQL
* What: Lets you ask for exactly what you want in one request.
* Example: Instead of getting all post details, you might say:
query {
posts(tag: "travel") {
title
date
}
}
* Response: Only titles and dates—no extra fluff!
* Advantages: Efficient, flexible.
* Disadvantages: Harder to set up than REST.
SOAP
* What: Uses XML (a stricter format) and is common in big businesses.
* Example: A bank might use SOAP to securely fetch user data—not our blogging
app, though!
* Advantages: Reliable, secure.
* Disadvantages: Complex, heavy.
WEBHOOKS
* What: The server “calls back” when something happens.
* Example: When a new post is added, the API notifies a subscriber app (e.g., a
news feed) instantly.
* Advantages: Real-time updates.
* Disadvantages: Tricky to manage.
In our blogging app, we’ll stick with REST—it’s beginner-friendly and perfect
for fetching and managing posts.
--------------------------------------------------------------------------------
SECTION 4: ADVANCED EXAMPLE
For our app, imagine filtering posts by date:
* Request: GET https://myblog.com/api/posts?date=2025-03
* Response:
{
"posts": [
{"id": 1, "title": "My Trip to Paris", "date": "2025-03-01"},
{"id": 2, "title": "Hiking in Japan", "date": "2025-03-15"}
]
}
The API filters the database and sends only March posts. Cool, right?
--------------------------------------------------------------------------------
CONCLUSION: APIS IN ACTION
APIs are the unsung heroes of modern apps, connecting the dots between what you
see and where the data lives. Here’s what to remember:
* Key Takeaways: APIs let software talk, using requests and responses over
HTTP. They’re reusable, scalable, and integrate systems seamlessly.
* Best Practices: Use clear endpoints (like /api/posts), choose the right type
(REST for simplicity), and test with tools like Postman or curl.
* Pitfalls to Avoid: Don’t assume APIs “just work”—test them! And don’t
overload them with huge requests; keep them efficient.
In our blogging app, APIs fetch posts for users and save new ones for admins. As
you learn Node.js and React in this course, you’ll build APIs to power your own
projects. Next time you use an app, think: “There’s an API making this
happen!”—and now, you know how it works.
--------------------------------------------------------------------------------
This lecture builds the blogging app example step-by-step, surprises students
with misconceptions (e.g., APIs aren’t the app itself), and goes deep into
types, processes, and practical testing. It’s engaging, relatable, and sets a
strong foundation for further learning! Let me know if you’d like a slides
version instead.
Maggie is a generative AI that can help you understand the course content better. You can ask her questions about the lecture, and she will try to answer them. You can also see the questions asked by other students and her responses.
Join the discussion to ask questions, share your thoughts, and discuss with other learners