VibeKoding / Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat / An Introduction to APIs: Understanding Inter-Program Communication from ScratchAn Introduction to APIs: Understanding Inter-Program Communication from Scratch
VK

An Introduction to APIs: Understanding Inter-Program Communication from ScratchAn Introduction to APIs: Understanding Inter-Program Communication from Scratch

๐Ÿ“š Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat ๐ŸŒ Dual Bahasa (ID / EN) โšก VibeKoding Native

Ensiklopedia VibeKoding: An Introduction to APIs: Understanding Inter-Program Communication from Scratch.Ensiklopedia VibeKoding: An Introduction to APIs: Understanding Inter-Program Communication from Scratch.

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

What is an API? It's like asking: how should a restaurant design its menu so guests can understand it at a glance? How should waiters take orders without making mistakes? APIs solve the problem of "how programs communicate with each other." You've been using APIs since your first day of coding โ€” you just might not have realized it.What is an API? It's like asking: how should a restaurant design its menu so guests can understand it at a glance? How should waiters take orders without making mistakes? APIs solve the problem of "how programs communicate with each other." You've been using APIs since your first day of coding โ€” you just might not have realized it.

------

0. Three Common Confusions for Beginners0. Three Common Confusions for Beginners

Confusion 1: Are APIs something advanced?Confusion 1: Are APIs something advanced?

Many people think APIs are only for senior engineers. But you've already used APIs:Many people think APIs are only for senior engineers. But you've already used APIs:

python
len("hello") # This is a Python API open("file.txt") # This is also an API requests.get(url) # This is still an API

Confusion 2: What's the difference between Web APIs and regular APIs?Confusion 2: What's the difference between Web APIs and regular APIs?

TypeTargetCommunication MethodTypical Scenario
Function APILocal codeFunction calllen(), open()
OS APIOperating systemSystem callFile I/O, process creation
Web APIRemote serverHTTP requestCalling AI models, getting weather

Confusion 3: Should I use HTTP or SDK?Confusion 3: Should I use HTTP or SDK?

python
# HTTP approach: handle all details yourself import requests response = requests.post( "https://api.deepseek.com/v1/chat/completions", headers={"Authorization": "Bearer sk-xxx"}, json={"model": "deepseek-chat", "messages": [...]} ) result = response.json()["choices"][0]["message"]["content"] # SDK approach: let the butler handle it from openai import OpenAI client = OpenAI(api_key="sk-xxx") response = client.chat.completions.create( model="deepseek-chat", messages=[...] ) result = response.choices[0].message.content

------

1. The Essence of APIs: Plugs and Sockets1. The Essence of APIs: Plugs and Sockets

API (Application Programming Interface) is simply the "agreement for communication between programs."API (Application Programming Interface) is simply the "agreement for communication between programs."

1.1 Appliance Analogy1.1 Appliance Analogy

ConceptAppliance AnalogyAPI Equivalent
InterfaceSocket shapeFunction signature / URL
InputElectrical current inputFunction parameters / Request body
OutputAppliance operatesReturn value / Response body

1.2 Three Types of API Comparison1.2 Three Types of API Comparison

1.3 Function API vs HTTP API: What's the Difference1.3 Function API vs HTTP API: What's the Difference

Many beginners wonder: what's the real difference between function APIs and HTTP APIs? How to tell them apart when reading documentation?Many beginners wonder: what's the real difference between function APIs and HTTP APIs? How to tell them apart when reading documentation?

1.4 How to Read Different Types of API Documentation1.4 How to Read Different Types of API Documentation

Different types of API documentation have different focus areas:Different types of API documentation have different focus areas:

------

2. A Complete API Call2. A Complete API Call

๐Ÿ‘‡ Try it out: Click the button below to observe a complete API request-response flow:๐Ÿ‘‡ Try it out: Click the button below to observe a complete API request-response flow:

2.1 Four Stages of an API Call2.1 Four Stages of an API Call

StageWhat HappensAppliance Analogy
RequestClient sends request to serverPressing a switch
TransmissionRequest travels through network to serverCurrent flows through wires
ProcessingServer processes request and returns dataAppliance starts working
ResponseClient receives and processes the resultLight bulb lights up

2.2 Restaurant Analogy2.2 Restaurant Analogy

Restaurant RoleAPI EquivalentDescription
MenuAPI DocumentationTells you what "dishes" are available
WaiterHTTP ProtocolStandardized "way of communicating"
KitchenServerProcesses requests based on "orders"
Serving FoodResponseReturns results to the "guest"

------

3. HTTP Methods: Overview of You "Asking" or "Doing"3. HTTP Methods: Overview of You "Asking" or "Doing"

When calling a Web API, you need to tell the server what you want to do. That's where HTTP methods come in.When calling a Web API, you need to tell the server what you want to do. That's where HTTP methods come in.

3.1 Restaurant Ordering Analogy3.1 Restaurant Ordering Analogy

ScenarioWhat would you say in real life?HTTP Method
You want to see today's menu"Waiter, let me see the menu"GET - Pure "asking", doesn't modify data
You want to order Kung Pao Chicken"I'll have the Kung Pao Chicken"POST - "Doing" something, creates data
You want to change your dish"Change Kung Pao Chicken to Sweet and Sour Pork"PUT - Replace data
You want to change the flavor"No peanuts in the Kung Pao Chicken"PATCH - Partial modification
You don't want it anymore"Never mind, cancel that dish"DELETE - Delete data

โš ๏ธ Catatan Keamanan / Peringatanโš ๏ธ Warning / Security Note

Idempotency: Do multiple executions produce the same result? - Idempotent operations (GET/PUT/DELETE): Clicking 10 times produces the same result as clicking once - Non-idempotent operations (POST): Clicking 10 times might create 10 orders Solution: Use unique IDs for POST operations to prevent duplicate processing.Idempotency: Do multiple executions produce the same result? - Idempotent operations (GET/PUT/DELETE): Clicking 10 times produces the same result as clicking once - Non-idempotent operations (POST): Clicking 10 times might create 10 orders Solution: Use unique IDs for POST operations to prevent duplicate processing.

3.2 HTTP Methods Quick Reference3.2 HTTP Methods Quick Reference

MethodPurposeIdempotentSafeTypical Scenario
GETRetrieve resourceYesYesQuery lists, view details
POSTCreate resourceNoNoAdd user, submit order
PUTFull updateYesNoReplace entire user profile
PATCHPartial updateNoNoOnly modify nickname
DELETEDelete resourceYesNoDelete user, cancel order

------

4. HTTP Status Codes: Overview of the Server Telling You4. HTTP Status Codes: Overview of the Server Telling You

When the server responds, it first returns a status code telling you whether the request was successful.When the server responds, it first returns a status code telling you whether the request was successful.

4.1 Status Code Categories4.1 Status Code Categories

4.2 Common Status Codes Explained4.2 Common Status Codes Explained

Status CodeMeaningTypical ScenarioClient Handling
200 OKSuccessRequest processed normallyDisplay data
201 CreatedCreated successfullyPOST request successfully created resourceRedirect to new resource
400 Bad RequestRequest format errorMissing or malformed parametersCheck parameters
401 UnauthorizedUnauthenticatedNo valid API Key providedGuide user to login
403 ForbiddenNo permissionAPI Key doesn't have access to this resourceShow insufficient permissions
404 Not FoundNot foundRequested address or resource doesn't existCheck URL
429 Too Many RequestsToo many requestsExceeded rate limitRetry later
500 Internal Server ErrorServer errorServer-side problemTell user to retry later

๐Ÿ‘‡ Try it out: Click the button below to learn about common status codes:๐Ÿ‘‡ Try it out: Click the button below to learn about common status codes:

------

5. HTTP vs SDK: Run Errands Yourself or Let the Butler Handle It5. HTTP vs SDK: Run Errands Yourself or Let the Butler Handle It

5.1 Two Calling Methods Compared5.1 Two Calling Methods Compared

๐Ÿƒ HTTP API๐Ÿคต SDK
AnalogyRunning errands yourselfButler handles it
Prosโœ“ Works with any language
โœ“ Full control over request details
โœ“ No additional dependencies
โœ“ Clean, readable code
โœ“ Automatic authentication
โœ“ Built-in error retry
Consโœ— Need to handle all details
โœ— Verbose and error-prone code
โœ— Need to install dependencies
โœ— May have version issues
Code Examplerequests.post(url, json=..., headers={...})client.chat.completions.create(...)

5.2 Approach to choosing5.2 Approach to choosing

ScenarioRecommended ApproachReason
Rapid developmentSDKHandles authentication, errors, and retries automatically
Learning principlesHTTPUnderstand underlying mechanisms
Unsupported languageHTTPWorks with any language
Need customizationHTTPFlexible control over every detail
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

Use SDK when available. Leave the hassle to the library, save time for yourself.Use SDK when available. Leave the hassle to the library, save time for yourself.

------

6. Approach to reading API Documentation6. Approach to reading API Documentation

API documentation is like a combination of a manual and a menu. You don't need to read it cover to cover โ€” just learn how to "look things up in a dictionary."API documentation is like a combination of a manual and a menu. You don't need to read it cover to cover โ€” just learn how to "look things up in a dictionary."

6.1 Documentation Reading Checklist6.1 Documentation Reading Checklist

Open any API documentation (like OpenAI or DeepSeek), and you only need to find these things:Open any API documentation (like OpenAI or DeepSeek), and you only need to find these things:

ItemDescriptionExample
Base URLRoot address of the APIhttps://api.deepseek.com
AuthenticationHow to prove your identityAuthorization: Bearer sk-xxx
EndpointsSpecific endpoint list/v1/chat/completions
ParametersRequired/optional parametersmodel (required), temperature (optional)
ResponseReturn data structure{"choices": [...]}

6.2 Steps to Read Documentation6.2 Steps to Read Documentation

  1. Find the Base URL - This is the prefix for all requestsFind the Base URL - This is the prefix for all requests
  2. Understand the authentication method - Is the API Key in the Header or Query?Understand the authentication method - Is the API Key in the Header or Query?
  3. Find the Endpoint you need - The specific endpoint you want to callFind the Endpoint you need - The specific endpoint you want to call
  4. Check request parameters - Which are required? Which are optional?Check request parameters - Which are required? Which are optional?
  5. Understand the response format - How is the data organized?Understand the response format - How is the data organized?
  6. ------

    7. Hands-on Practice: Simulate API Calls7. Hands-on Practice: Simulate API Calls

    Practice makes perfect. Here's a simulated API where you can fill in any parameters and change any address to see what happens.Practice makes perfect. Here's a simulated API where you can fill in any parameters and change any address to see what happens.

    Try triggering these scenarios:Try triggering these scenarios:

    • โœ… Successful request: Enter the correct Endpoint and API Keyโœ… Successful request: Enter the correct Endpoint and API Key
    • โŒ 401 Error: Don't enter an API Key and see how the server rejects youโŒ 401 Error: Don't enter an API Key and see how the server rejects you
    • โŒ 404 Error: Enter a non-existent addressโŒ 404 Error: Enter a non-existent address

    ------

    8. Summary8. Summary

    ๐Ÿ“– Konsep Penting๐Ÿ“– Core Concept

    1. APIs are like megaphones, helping you pass messages to other code or remote servers 2. You've already used APIs, from len() to open(), they're all APIs 3. Web APIs are superpowers, letting you call supercomputers thousands of miles away 4. SDKs are good butlers, use SDKs when available instead of running errands yourself 5. Look for three things in documentation: address, authentication, and parameters1. APIs are like megaphones, helping you pass messages to other code or remote servers 2. You've already used APIs, from len() to open(), they're all APIs 3. Web APIs are superpowers, letting you call supercomputers thousands of miles away 4. SDKs are good butlers, use SDKs when available instead of running errands yourself 5. Look for three things in documentation: address, authentication, and parameters

    In the era of AI programming, you only need to remember these core concepts. The rest of the details will be handled by your IDE and AI assistant.In the era of AI programming, you only need to remember these core concepts. The rest of the details will be handled by your IDE and AI assistant.

    ------

    GlossaryGlossary

    TermFull NameExplanation
    APIApplication Programming InterfaceApplication programming interface, defines how software interacts
    Web API-HTTP-based API for network communication
    Endpoint-Endpoint, the specific address of an API
    HTTPHyperText Transfer ProtocolCommunication protocol used by Web APIs
    GET-Method for retrieving resources
    POST-Method for submitting data
    SDKSoftware Development KitSoftware development kit that wraps underlying API calls
    URLUniform Resource LocatorNetwork address of an API
    JSONJavaScript Object NotationCommonly used data format
    Authentication-Process of verifying identity
    Status Code-Status code in HTTP responses
    Request-Request
    Response-Response
    Header-HTTP header containing metadata
    Payload-Actual data in a request or response
    Rate Limit-Rate limiting
    Idempotent-Idempotent, multiple executions produce the same result
    RESTRepresentational State TransferAn API architectural style
    RPCRemote Procedure CallRemote procedure call
    GraphQL-A query language API
    gRPC-High-performance RPC framework developed by Google