Data interface

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Data interface

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which best describes a data interface?
A The agreed point where one system gives data to, or takes data from, another
B A screen that only shows data to the user
2. A school system saves attendance as a CSV file that the payroll system then imports. What type of interface is this?
A API-based interface
B File-based interface
3. A weather app sends a request to a web service and receives JSON in reply. What type of interface is this?
A File-based interface
B API-based interface
4. Which statement about the format of a data interface is correct?
A Both systems must agree on the input and output format, such as CSV or JSON
B Each system can choose its own format without telling the other
5. A receiving system expects dates as 2026-03-14 but the sending system outputs 14/03/26. What is the problem?
A The output format does not match the format the interface expects
B The interface has too many users

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1GET https://api.school.edu.au/students/101 AA request to an API-based data interface that asks the school system to hand back the record for one student
2students_export.csv BA file-based data interface where one system saves data in an agreed format for another system to read
3An interface defines the output format, so the receiving system knows exactly how the data will be structured C{"studentId": 101, "name": "Ava", "yearLevel": 12}
4An interface controls who can use it, so a system must prove who it is before it can take data DThe interface has no rule about who can use it. Anyone can take sensitive data, so access should be limited to approved, authenticated systems.
5Sender saves marks.csv with columns Name, Mark, Year. Receiver expects Year, Name, Mark. EThe two systems have not agreed on the interface format. The column order differs, so the receiver will read the wrong data into each field.
6A public API returns every student's address and health notes to any system that asks, with no login. FAuthorization: Bearer abc123token

Definitions

data interface

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
with open("orders.csv") as f: rows = list(___.reader(f))
2.
url = "https://api.school.au/marks" reply = requests.___(url)
3.
record = {"id": 7, "mark": 88} output = json._____(record)
4.
with open("export.csv", "_") as f: f.write("id,mark\n")
5.
headers = {"Authorization": "Bearer " + key} reply = requests.get(url, _______=headers)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A import json
B text = '{"name": "Ava"}'
C data = json.loads(text)
D print(data.name)
Question 2
A import csv
B f = open("out.csv", "r")
C w = csv.writer(f)
D w.writerow(["id", "mark"])
Question 3
A import requests
B h = {"x-api-key", key}
C r = requests.get(u, headers=h)
D print(r.status_code)
Question 4
A import json
B student = {"id": 7, "name": "Zoe"}
C out = json.loads(student)
D print(out)
Question 5
A import csv
B total = 0
C with open("sales.csv") as f:
D rows = csv.reader(f)
E for r in rows:
F total += int(r["amt"])

Answer Key

Data interface
Section A: Quick Questions
Q1
A — The agreed point where one system gives data to, or takes data from, another
Q2
B — File-based interface
Q3
B — API-based interface
Q4
A — Both systems must agree on the input and output format, such as CSV or JSON
Q5
A — The output format does not match the format the interface expects
Section B: Match the Pairs
Q1
GET https://api.school.edu.au/students/101 → A request to an API-based data interface that asks the school system to hand back the record for one student
Q2
students_export.csv → A file-based data interface where one system saves data in an agreed format for another system to read
Q3
An interface defines the output format, so the receiving system knows exactly how the data will be structured → {"studentId": 101, "name": "Ava", "yearLevel": 12}
Q4
An interface controls who can use it, so a system must prove who it is before it can take data → Authorization: Bearer abc123token
Q5
Sender saves marks.csv with columns Name, Mark, Year. Receiver expects Year, Name, Mark. → The two systems have not agreed on the interface format. The column order differs, so the receiver will read the wrong data into each field.
Q6
A public API returns every student's address and health notes to any system that asks, with no login. → The interface has no rule about who can use it. Anyone can take sensitive data, so access should be limited to approved, authenticated systems.
Section C: Definitions
Q1
data interface — The agreed point where one system gives data to, or takes data from, another. It sets the format and rules of the exchange, such as a file or an API.
Section D: Fill in the Blanks
Q1
with open("orders.csv") as f: rows = list(csv.reader(f))
Q2
url = "https://api.school.au/marks" reply = requests.get(url)
Q3
record = {"id": 7, "mark": 88} output = json.dumps(record)
Q4
with open("export.csv", "w") as f: f.write("id,mark\n")
Q5
headers = {"Authorization": "Bearer " + key} reply = requests.get(url, headers=headers)
Section E: Spot the Error
Q1
D — A JSON object becomes a Python dictionary, so a field is read with square brackets. It should be print(data["name"]).
Q2
B — This file is an output interface, so the program must write to it. The file must be opened in write mode "w", not read mode "r".
Q3
B — Headers must be a dictionary of name: value pairs. A comma instead of a colon makes a set, so the API key is not sent properly. It should be {"x-api-key": key}.
Q4
C — To send a dictionary in the agreed JSON output format, it must be turned into text with json.dumps(). json.loads() does the opposite and parses JSON text.
Q5
D — csv.reader gives each row as a list, so r["amt"] fails. The column name only works with csv.DictReader(f), which matches the file's header names.