-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Function to fetch GDC data using the API
async function fetchGDCData() {
// GDC API endpoint for retrieving projects data
const url = 'https://api.gdc.cancer.gov/projects';
// Set up query parameters (you can modify these to filter for specific data)
const params = {
size: 100, // Return only 10 projects for this example
};
try {
// Make the API request
const response = await fetch(url + '?' + new URLSearchParams(params));
// Check if the response is OK
if (!response.ok) {
throw new Error('Failed to fetch data from GDC API');
}
// Parse the JSON response
const data = await response.json();
// Log or process the data
console.log(data);
displayData(data);
} catch (error) {
console.error('Error:', error);
}
}
// Function to display fetched data on the web page
function displayData(data) {
const body = document.querySelector('body');
const title = document.createElement('h1');
title.innerText = 'GDC Projects';
body.appendChild(title);
const list = document.createElement('ul');
data.data.hits.forEach(project => {
const item = document.createElement('li');
item.innerText = project.project_id + ': ' + project.name;
list.appendChild(item);
});
body.appendChild(list);
}
// Call the function to fetch and display the data when the page loads
window.onload = fetchGDCData;