Gambaran Umum
API ini menyediakan akses ke soal-soal latihan TOEFL yang mencakup tiga kategori utama: Structure & Written Expression, Reading Comprehension, dan Listening Comprehension.
Base URL
Gunakan URL ini sebagai dasar panggilan API.
https://toefl-api.vercel.app
Tipe Konten
Semua request body dan respons dalam format JSON.
application/json
Endpoint API
/api/soal/:tipeSoal
Mengambil semua soal dari kategori tertentu.
Parameter Path:
tipeSoal (wajib): Ganti dengan
structure, reading, atau
listening.
/api/soal/:tipeSoal/random
Mengambil satu soal (atau satu paket soal untuk Reading/Listening) secara acak dari kategori tertentu.
Parameter Path:
tipeSoal (wajib): Ganti dengan
structure, reading, atau
listening.
/api/submit
Mengirimkan jawaban pengguna untuk dihitung skornya. Menerima array jawaban dari berbagai kategori.
Contoh Body Request:
[
{
"id": "s01",
"userAnswer": "B"
},
{
"id": "r01-q1",
"userAnswer": "A"
}
]
Contoh Respons:
{
"correctAnswers": 1,
"totalQuestions": 2,
"score": 50
}
Struktur Data
Soal Structure
{
"id": "s01",
"question": "The new shopping mall _____ next month after two years of construction.",
"options": {
"A": "will open",
"B": "will be opened",
"C": "is opening",
"D": "opens"
},
"correct_answer": "B"
}
Soal Reading
{
"passage_id": 1,
"passage_title": "Sustainable Development",
"passage_text": "The concept of sustainable development has gained significant attention in recent decades as societies worldwide grapple with environmental challenges and resource depletion. Sustainable development refers to meeting the needs of the present generation without compromising the ability of future generations to meet their own needs. This approach requires balancing economic growth, environmental protection, and social equity.\n\nOne of the key principles of sustainable development is the integration of environmental considerations into economic decision-making. Traditional economic models often prioritize short-term profits over long-term environmental consequences. However, sustainable development advocates argue that environmental degradation ultimately undermines economic prosperity by depleting the natural resources upon which economic activities depend.\n\nThe implementation of sustainable development practices requires cooperation between governments, businesses, and civil society. Governments play a crucial role in establishing policies and regulations that promote sustainable practices. Businesses must adopt environmentally responsible production methods and consider the long-term impacts of their operations. Meanwhile, civil society organizations help raise awareness and hold both governments and businesses accountable for their environmental commitments.",
"questions": [
{
"id": "r01-q1",
"question": "According to the passage, sustainable development is primarily concerned with:",
"options": {
"A": "Maximizing economic growth",
"B": "Protecting the environment at all costs",
"C": "Balancing present needs with future generations' needs",
"D": "Reducing government regulations"
},
"correct_answer": "C"
}
]
}
Soal Listening
{
"dialog_id": 1,
"dialog_title": "Academic Advisor Meeting",
"dialog_script": "/static/audio/dialog/dialog1.mp3",
"questions": [
{
"id": "l-d01-q1",
"question": "What is Sarah's main problem?",
"options": {
"A": "She doesn't understand statistics",
"B": "She has scheduling conflicts with required courses",
"C": "She doesn't like her advisor",
"D": "She wants to change her major"
},
"correct_answer": "B"
}
]
}
Contoh Penggunaan
JavaScript (API Fetch)
const BASE_URL = 'https://toefl-api.vercel.app';
// Mengambil soal structure acak
fetch(`${BASE_URL}/api/soal/structure/random`)
.then(response => response.json())
.then(data => console.log(data));
// Mengirim jawaban untuk dihitung
const userAnswers = [
{ id: 's01', userAnswer: 'B' },
{ id: 'r02-q1', userAnswer: 'A' }
];
fetch(`${BASE_URL}/api/submit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userAnswers)
})
.then(response => response.json())
.then(result => {
console.log(`Skor Anda: ${result.score}%`);
});
Penanganan Error
Terjadi saat meminta resource yang tidak ada (mis. tipe soal).
{
"message": "Tipe soal tidak
ditemukan!"
}
Terjadi saat validasi data gagal (mis. email sudah terdaftar).
{
"message": "Validasi gagal.",
"errors": {
"email": [
"Email sudah terdaftar."
]
}
}
Terjadi saat format request salah (mis. bukan JSON array).
{
"message": "Format input
harus berupa array!"
}
Ringkasan Kategori Soal
Structure
Soal tata bahasa dan ekspresi tulisan.
30 SoalReading
Pemahaman bacaan dengan beberapa teks.
6 Bacaan, 30 SoalListening
Pemahaman audio dialog dan monolog.
9 Audio, 40 Soal