Combining Multiple Filters
To build a production-grade CBT application, you will rarely use just one filter. Your users will want to select a specific subject, from a specific exam, in a specific year, and receive a batch of questions all at once.
Building the Ultimate Query
2.13.1In standard HTTP GET requests, you combine query parameters using the ampersand (&) symbol. Let's say a student wants to practice 40 JAMB Physics questions from the year 2019.
GET https://sdashapi.com/api/v1/q?subject=physics&type=utme&year=2019&limit=40
This single HTTP request securely passes four different parameters to the SdashAPI backend, returning a tightly controlled JSON array.
Dynamic URL Construction in JavaScript
2.13.2Instead of manually concatenating strings with plus signs, which can lead to formatting errors, you should use the native URL and URLSearchParams APIs available in modern JavaScript.
const url = new URL('https://sdashapi.com/api/v1/q');
const params = {
subject: 'chemistry',
type: 'wassce',
year: 2022,
limit: 20
};
// Automatically formats the ? and & symbols
url.search = new URLSearchParams(params).toString();
fetch(url, { headers: { "AccessToken": "YOUR_KEY" } })
.then(res => res.json())
.then(data => console.log(data));Filter Precedence
2.13.3The order in which you append the query parameters (e.g., placing year before subject) does not matter to the server. The SdashAPI backend will parse the parameters regardless of their order in the URL.