Webinar topic: Introduction to APIs: What, Why, and How?


Introduction to APIs 

 What, Why, and How....the APIs?


🎯 Learning Objectives:

By the end of this lecture, students will be able to:

  • Understand what an API is and how it fits into modern software architecture

  • Discover why APIs are essential in scalable, modular systems
  • Explain why APIs are used in software development.
  • Identify how APIs work with real-life examples.
  • Explore different types of APIs (REST, SOAP, Web, OS, Hardware, etc.)
  • Experiment with APIs using tools like Postman and curl

🔍 1. What is an API?

✅ Definition:

API stands for Application Programming Interface.

It is a set of rules and protocols that allows one software application to interact/talk with one another.

Simple Example:
An API is like a waiter in a restaurant:

·        You (client) place an order (request)

·        The waiter (API) delivers it to the kitchen (server)

·        The kitchen prepares the food (data/service)

·        The waiter brings it back to you (response)

 


That’s exactly how an API works between apps and servers.


✅ Example:

Suppose you're using a weather app:

·        It sends a request via API to a weather server (e.g., OpenWeatherMap)

·        The server returns data like temperature, humidity, wind speed

·        The app displays this information to the user


An API (Application Programming Interface) is a contract between two software systems, defining how they communicate through requests and responses. It abstracts internal complexity, allowing developers to use features or data without knowing the internal code.

🧠 Layman’s Analogy

Think of an API as a power plug:

·        You don’t need to know how electricity is generated.

·        You just plug in your device (client) and it works.

·        The socket (API) provides a standard interface to access a complex system.


🧾 Developer Example

Suppose you're building a weather dashboard:

fetch('https://api.openweathermap.org/data/2.5/weather?q=Delhi&appid=YOUR_API_KEY')

  .then(res => res.json())

  .then(data => console.log(data));

You’re using the weather service, but you don’t manage the satellite, sensors, or databases.


What is API in web development?

An API (Application Programming Interface) is like a universal connector. It allows different software systems to talk to each other, regardless of the operating system (Windows, macOS, Linux, etc.).

In web development, APIs act like a universal bridge between frontend and backend systems. Whether you’re on Windows, macOS, Linux, Android, or iOS — APIs help standardize communication.

So yes, when we use an API:

·        We write the code once to interact with that API,

·        And the API takes care of the OS-level differences.

🧠 Example to Understand Better:

Imagine you are building an app that needs to save a file.

Without API:

You’d need to write different code for:

·        Windows (uses C:\path\to\file)

·        Linux/Mac (uses /path/to/file)

So your code would need to handle every OS separately.

With API (like using a File System API):

fs.writeFile('notes.txt', 'Hello!', callback);

And the API handles the differences internally.


🔁 Real-world API Examples:

API

Used For

Works on

Fetch API in JavaScript

Getting data from the internet

Any browser (Windows, macOS, Linux)

Java APIs

File access, networking, etc.

Java runs on all OS

React Native API

Build mobile apps

Android & iOS

REST API

Web communication

Any OS or device


Yes, APIs help developers write one piece of code that works across different platforms and operating systems by hiding the complexity of OS-specific operations.




🔎 2. Why Use APIs?

🔗 1. Integration Between Systems

APIs allow different software systems to communicate and share data.

Here API connect external services.

Example: Google Maps API can be integrated into a delivery app to track location.


🧱 2. Reusability

APIs are reusable building blocks. You don’t have to build everything from scratch.

Reuse the code via intefaces.

Example: Use a Payment Gateway API (like Razorpay or Stripe) instead of creating your own payment system.


🚀 3. Faster Development

APIs speed up development time by using prebuilt features.

Use prebuilt functions and data

Example: Firebase API helps to add authentication (login/signup) in just minutes.

AWS Rekognition


🛡 4. Security

APIs provide controlled access to services. Users only get access to what is allowed.

Example: A public API key can give access to limited data only.


📱 5. Support for Mobile and Web Apps

APIs allow mobile apps, web apps, and even IoT devices to connect to the same backend server.

📱 6.Modularity

Break large apps into microservices

Example: Auth service, Product service, etc.

⚙️ 3. How Do APIs Work?

📬 Step-by-step Process:

1.  Client sends a request to the server via API.

2. The API processes the request, applies logic, and interacts with the database or service.

3.The API sends a response back to the client (usually in JSON format).

🌍 API Communication Cycle

1.   Client (frontend/app) sends an HTTP request to an API endpoint.

2.   The API server processes the request (may talk to databases or services).

3.   A response is returned, typically in JSON or XML format.

📊 Example – Currency Exchange API

Request:

GET https://api.exchangerate-api.com/v4/latest/USD

Response:

{

  "base": "USD",

  "rates": {

    "INR": 83.24,

    "EUR": 0.92,

    ...

  }

}

 🧪 API = Contract

Each API is a contract that defines:

·        URL structure (endpoint)

·        Allowed HTTP methods (GET, POST, PUT, DELETE)

·        Request format (headers, parameters, body)

·        Response format (status codes, data schema)

🔁 Common Actions via API:

APIs commonly use HTTP methods like GET, POST, PUT, and DELETE — which are very similar to CRUD operations in databases."


Action

HTTP Method

Description

GET

Fetch data

View or read data

POST

Create data

Add a new entry

PUT

Update data

Edit existing entry

DELETE

Delete data

Remove data


🧰 4. Types of APIs

📗 a. Open/Public APIs

  • Available to everyone.
  • Example: OpenWeatherMap, Google Maps API

🔒 b. Private APIs

  • Used internally within an organization.
  • Example: An API to access employee database in a company.

👥 c. Partner APIs

  • Shared with business partners with authentication.
  • Example: Travel APIs between airlines and booking apps.

🔁 d. Composite APIs

  • Combine multiple API calls into one.means combine multiple services into one call.

🌐 5. REST vs SOAP APIs

There are two common types of API stylesREST and SOAP.

----REST uses JSON, and it’s lightweight and fast.

----SOAP is more structured, but heavier as it uses XML.

----Most modern apps — like mobile apps and websites — use REST APIs because they are easy to use.


Feature

REST

SOAP

Protocol

HTTP

XML-based protocol

Format

JSON (mostly), XML

Only XML

Speed

Faster

Slower

Simplicity

Easy to understand & use

Complex

Usage

Web services, mobile apps

Enterprise applications

For modern web and mobile apps, REST APIs are most popular.


🧪 6. Real-Life Examples of APIs

Let me share some real-life examples of how apps use APIs:


App or Website

Uses Which API?

Functionality

Swiggy/Zomato

Google Maps API

Show restaurant location

Instagram

Facebook API

Login & share content

Paytm

Bank/UPI APIs

Handle payments

Weather App

OpenWeatherMap API

Display weather info


🛠️ 7. Tools to Explore APIs and Test API

Tool

Use

Postman

Send API requests and test them

Swagger

API documentation and testing

curl (CLI)

Command-line API request tool

Insomnia

REST Client like Postman

These tools help you learn, test, and understand how APIs work — without writing much code.


1. 🧪 Postman

  • What it is: A popular API testing tool with a simple interface.
  • Use:
    • Send API requests (GET, POST, etc.)
    • View and analyze responses.
    • Test APIs without writing code.
  • Great for: Beginners and professionals alike....All developers

🔍 Example: You can test https://api.agify.io/?name=rahul in Postman by just pasting the URL and clicking Send.


2. 📄 Swagger (OpenAPI)

  • What it is: A documentation and testing tool for APIs.
  • Docs + Try-out for REST APIs

  • Use:
    • View complete API details: URL, parameters, methods.
    • Try out the API directly in the browser.
  • Great for: Understanding how an API works from a developer or client side.

    Backend devs, testers

🔍 Many websites give Swagger UI to test their API without Postman.


3. 💻 curl (Command Line Tool)

  • What it is: A command-line utility to send API requests.
  • Use:
    • Make API requests from your terminal.
    • Useful for quick testing by developers.
  • Great for: Those who are comfortable with terminal/CLI.  Linux/power users

🔍 Example:

curl https://api.agify.io/?name=rahul


4. 🌙 Insomnia

  • What it is: A REST client, very similar to Postman.
  • Use:
    • Create and test API requests.
    • Clean and simple interface.
  • Great for: Developers who want a lightweight and fast Postman alternative.

    Web devs, students

 


💡 8. Basic API Request Example

➕ Example: GET Request (Using browser or Postman)

URL:

https://api.agify.io/?name=rahul

This API predicts the age of a person based on their name.

Steps:

1.   Open Postman.

2.   Paste the above URL.

3.   Choose GET method.

4.   Click Send.

Response:

{

  "name": "rahul",

  "age": 29,

  "count": 1234

}

📌 9. Summary

1. APIs allow software components to talk to each other in a standard, secure way.

2. REST APIs are preferred for modern development due to simplicity and speed.

3. APIs reduce complexity, increase reusability, and enable rapid development.

4. Tools like Postman and Swagger help test and explore APIs easily.

5. Understanding API documentation is crucial for professional development.


️ Homework / Practice:

1. Identify 5 websites or apps you use daily and find out what APIs they might use.

2.  Visit https://rapidapi.com and explore at least 2 free APIs.

3.  Try calling a simple public API (like Agify) using your browser or Postman.


🔎 1. Identify 5 Websites or Apps You Use Daily

This task helps you connect your daily app usage with real-world API usage. Most apps use multiple APIs to give you the features you enjoy.

📝 Step-by-Step:

1.   List 5 apps or websites you use every day.
Examples:

o   WhatsApp

o   Swiggy

o   Instagram

o   Paytm

o   YouTube

2.   Think or search about what kind of APIs each of them might use.


✅ Answers

App Name

Possible APIs Used

What It Does

WhatsApp

End-to-End Encryption API, Chat Media API

Secure message delivery, media file handling

Swiggy

Google Maps API, Payment Gateway API

Track orders, make payments

Instagram

Facebook Login API, Image Filter API

Login with Facebook, apply filters to photos

Paytm

UPI API, Bank API, OTP Verification API

Do transactions, verify mobile number

YouTube

YouTube Data API, Google Ads API

Show videos, ads, and search suggestions


🔍 Tips for Students

·        You can search on Google like:What APIs does Swiggy use? or Instagram API examples

·        Visit developer pages of platforms like:

o   developers.facebook.com

o   developers.google.com/youtube

o   developer.paytm.com


🎯 What You Learn

·        How APIs power the apps you use.

·        How common services like login, payments, maps, and media are handled.

·        How companies don’t build everything from scratch, but instead connect services using APIs.


2. 🌐 Explore 2 Free APIs on RapidAPI

·        Go to 👉 https://rapidapi.com

·        Search for any category like:

o   Jokes

o   Quotes

o   Weather

o   News

👉 Task: Select two interesting APIs and read their description, URL, and usage.

📌 Example:

·        "JokeAPI" gives you random jokes.

·        "WeatherAPI" gives current weather data of any city.


3. 🧪 Try a Public API

You can test a public API using either a browser or Postman.

API to Try:https://api.agify.io/?name=rahul

👉 Task:

·        Replace “rahul” with your name.

·        See how the age prediction changes.

·        Optional: Try the same in Postman.

📌 Output will look like:

{ "name": "rahul", "age": 29, "count": 1540 }


4. 🗣️ “How Does a Weather App Use APIs?”

👉 Task:

·        how a weather app works using APIs.

·        Include:

o   What data it fetches (temperature, humidity, etc.)

o   From where? (Weather API like OpenWeatherMap)

o   How does the app display the data?


No comments:

Post a Comment