Front end and back end
Diperkenalkan
21:11
Komputasi III: Membangun, Mengkuery, dan Menjelaskan Aplikasi Web Database
Komputasi III meminta Anda untuk menghubungkan situs web ke data dan menggunakan SQL untuk mendukung pengambilan keputusan. Pertanyaan praktis kami adalah kelas mana yang masih memiliki tempat kosong. Catatan-catatannya…
Narasi bahasa Inggris · takarir bahasa Inggris dan 中文 yang dapat dipilih
Dalam pelajaran ini
| English | Makna |
|---|---|
| server/ˈsɜːvə/ | |
| request/rɪˈkwest/ | permintaan |
| response/rɪˈspɒns/ | respons |
| front end/frʌnt end/ | antarmuka depan |
| back end/bæk end/ | antarmuka belakang |
| API/ˌeɪ piː ˈaɪ/ | |
| JSON/ˈdʒeɪsn/ |
885 million documents behind a changed number, 2019
- In May 2019 the journalist Brian Krebs reported that the US title-insurance company First American had left about 885 million records — bank details, tax documents — reachable online. A customer's link contained a document number; changing the number showed other people's documents, because the server never checked who was asking.
- Every web app sends a request 请求 to a server 服务器 and receives a response 响应. The server must decide what each user may see.
What went wrong at First American in 2019?
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Changing a number showed others' records.
Front end and back end
- The front end 前端 runs in the browser or app: pages, buttons, forms. The back end 后端 runs on the server: business rules, the database, security checks.
- Anything in the front end can be changed by the user, so security checks belong in the back end.
Match each job to front end or back end.
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Security belongs on the server.
APIs
- An API 应用程序接口 is an agreed set of requests a program can make: for example
GET /api/courses/42asks for course 42. - The response has a status code — 200 OK, 401 not logged in, 403 not allowed, 404 not found — and usually a body.
Match each status code to its meaning.
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Codes tell the front end what happened.
JSON
- Most web APIs send data as JSON 数据交换格式: names and values in braces, such as
{"id": 42, "title": "Databases", "places": 30}. - JSON is plain text, so both front end and back end in any language can read it.

One request, different server and browser states
A valid ID is not permission. Compare a confirmed empty list with a denied request, a failed lookup and a missing response; the interface must preserve these differences.
Which is valid JSON?
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Names and values in braces, names in double quotes.
Worked example: one request, two checks
A student's app sends GET /api/grades/1057.
- Identity: is there a valid login token? No → 401.
- Permission: is student 1057 this user, or is the user their teacher? No → 403.
- Selection: return only the fields needed — module and grade, not the whole student record — as JSON with 200 OK.
A logged-in student asks for another student's grades. Which status code fits?
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Logged in, but not allowed.
Requests take time
- A response can be slow or fail. The front end shows a loading state, then the data or a clear error message.
- Never assume the network always works.
A front end should show a loading state and handle errors.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Networks are slow or fail.
Hiding a button is not security. First American's links "looked" private; anyone could change the number. The server must check permission on every request.
Hiding a button in the front end stops users reaching the data.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
They can send the request directly.
The front end sends requests through an API; the back end checks identity and permission, then returns a response with a status code and JSON data — only what that user may see.
A timetable app requests GET /api/timetable/88. Describe the checks the server should make and what it returns.
Identity, permission, selection.
Apa yang salah? Hanya tim situs yang dapat melihatnya.