Computer science core / Languages, databases, and APIs
From source code to an API
Connect interpreters, compilers, databases, and HTTP APIs in one product story.
Perkiraan waktu: 30 menit
Learning outcome
By the end of this lesson, you will be able to trace how source code becomes a running API — through interpreters, compilers, databases, and HTTP.
The journey from code to product
When you write a program and put it on the internet, it goes through several transformations:
flowchart TD
A[Source code] --> B{Interpreted or compiled?}
B -->|Interpreted| C[Python / JavaScript<br/>Read and run line by line]
B -->|Compiled| D[C / Rust / Go<br/>Translated to machine code]
C --> E[Running process]
D --> E
E --> F[Listens for HTTP requests]
F --> G[Queries database]
G --> E
E --> H[Returns JSON or HTML]
Interpreted vs compiled
Interpreted languages
Python, JavaScript, and Ruby are interpreted. A program called an interpreter reads your source code and runs it directly, one line at a time. This makes them easier to debug and faster to iterate, but slower at runtime.
Compiled languages
C, Rust, and Go are compiled. A compiler translates your entire source code into machine code before you run it. The result is a binary file that runs directly on the CPU. This makes them faster but harder to change quickly.
What is an API?
API stands for Application Programming Interface. It is a set of rules that one program uses to talk to another.
A web API listens for HTTP requests (like the ones your browser sends) and returns data, usually in JSON format:
GET /api/users
Response: [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
What is a database?
A database stores structured data and lets you query it efficiently. Most web applications use a relational database like PostgreSQL (which this site uses).
Your server code sends SQL queries to the database:
SELECT name, email FROM users WHERE id = 1;
The database returns matching rows, and your server sends them to the browser as JSON.
How they fit together
- You write Python source code.
- Python interprets it and starts a server process.
- The server listens on a port (like
:8000) for HTTP requests. - A browser sends
GET /api/users. - The server runs
SELECT * FROM usersagainst PostgreSQL. - The database returns rows.
- The server formats them as JSON and sends the response.
Common beginner mistakes
- Confusing a compiler with an interpreter. Python does not compile your code to machine code. It reads and runs it live.
- Thinking the database lives in the same process. The database is a separate program, often on a different machine. Your server talks to it over the network.
- Writing business logic in the database. Keep logic in your application code. The database should store and retrieve data.
Practice task
Install a simple Python web framework like Flask. Write a route GET /hello that returns {"message": "Hello, world!"}. Run it and visit http://localhost:5000/hello in your browser.
Recap
- Interpreted languages run line by line. Compiled languages become machine code first.
- An API is a set of rules for programs to communicate.
- A database stores structured data that your server queries.
- A web application connects all three: source code → server → database → HTTP response.
Next step
Now that you understand the full stack, the next lesson guides you through shipping a small useful project to test which development direction fits you.