From 0abdf42280b77c2499c869a054872ec8f9e14c08 Mon Sep 17 00:00:00 2001 From: Clarence Chan Date: Sun, 29 Oct 2023 10:31:39 -0400 Subject: [PATCH] Implement fetchEvent function in api.js --- api.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 api.js diff --git a/api.js b/api.js new file mode 100644 index 00000000..d63fb41d --- /dev/null +++ b/api.js @@ -0,0 +1,20 @@ +/** + * Returns the details of a UFC event given its event ID and using the UFC API + * + * @param {number} eventId - The ID of a UFC event + * @returns {Promise} - A Promise that resolves with the details of + * a UFC event + */ +async function fetchEvent(eventId) { + try { + const url = + "https://d29dxerjsp82wz.cloudfront.net/api/v3/event/live/" + + eventId + + ".json"; + const response = await fetch(url); + const event = await response.json(); + return event; + } catch (error) { + console.error(error); + } +}