When using the AI currently in service, you'll likely try using the API. Before using the API, understanding its role and basic concepts will greatly help you utilize it more effectively.
This article explains the concepts of APIs and databases (DB) in a simple and clear way.
An API doesn't store data directly; it acts as a "mediator for sending and receiving.
" To store data permanently, you need to connect it to a database (DB).
1. APIs don't store data—they act as a "data conduit"!
An API is essentially a data conduit (messenger). Simply put, it facilitates the exchange of data between clients (websites, apps) and servers (backend).
📌 Example Scenario (Drama Review System)
To understand how an API actually works, let's use a "drama review system" as an example.
1️⃣ User leaves a review for "My Mister".
→ The user writes the review on the website and clicks the submit button.
2️⃣ The API receives the user's request and stores it in the database (DB).
→ The API receives the data and saves it to the server's DB.
3️⃣ Another user requests, "Show me reviews for
'My Mister'!" → The API retrieves the drama review from the DB and delivers it to the user.
4️⃣ The user views the review data.
→ The website displays the data delivered by the API.
📌 Important Concept!
- ✅ The API itself does not store data!
- ✅ The API only retrieves data from the DB or puts data into the DB.
- ✅ To persistently store data, you need a database (DB)!
The API itself does not store data; it only fetches or inserts data from/into the DB. To persistently store data, you need a DB (database). Major DBs include MySQL and MariaDB.
Think of a DB as a storage system that efficiently manages data and enables integration with programs. The core of storage management, or DB management, is SQL. SQL can be categorized into two types: relational databases and non-relational databases. We'll explore database details in more depth below.
2. API + Database (DB) connection is required.
For an API to exchange data properly, it must be connected to a database (DB). Let's now understand how APIs and DBs work together.
Basic Role of an API (Request & Response)
API Request → "Please store this data in the DB!"
API Response → "I'll retrieve this data from the DB and display it!"
- ✅ When storing data (when a user leaves a review): The API receives the data and stores it in the DB
- ✅ When retrieving data (when a user views a review): The API fetches the data from the DB and delivers it to the user
For example, when writing a Netflix review, the review is stored in the database. When a user wants to view reviews, the database delivers the data to the user, allowing them to see reviews written by other users.
3. The API doesn't store data—the database does!
✔️ Key concept: The API "moves" data, while the database "stores" it.
📌 What if there's no DB?
- Even if the API receives data, it has nowhere to store it, so the data vanishes! 😱
- For example, if a user leaves a review but there's no DB, refreshing the page would make the data vanish.
📌 How to keep data stored?
- An API is merely an "intermediary" and has no data storage capability.
- To persistently store data, you must always use API + DB together.
4. What is a Database (DB)?
A database (DB) is a storage system that permanently stores data.
- All data you see on websites or apps like Naver (member information, posts, comments, reviews, etc.) is stored in a DB.
- The API plays the role of putting data into or retrieving data from this DB.
- Features of a DB
- ✅ Can store data permanently
- ✅ Easily manages large volumes of data
- ✅ Multiple users can access it simultaneously
📌 Example: Drama review database
| ID | User | Drama Title | Rating | Review Content |
|---|---|---|---|---|
| 1 | content | My Mister | ⭐⭐⭐⭐⭐ | It was such a moving drama T_T |
| 2 | flow | Mr. Sunshine | ⭐⭐⭐⭐☆ | You can't watch it without tears… |
As described above, when a user writes a rating and review for a drama title, it is stored in the AP RK database. This allows other users to view the review later when they access it.
