You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 3
Next »
Course Overview API
The code then makes a GET request to the /api/course
API endpoint using the fetchWithCache
function. This function appears to cache requests to reduce unnecessary API calls. It sends a query with the course's prefix
and number
as URL parameters (after encoding them for safety), for example, /api/course?prefix=CS&number=101
.
The fetchWithCache
function takes in three main arguments:
The URL with query parameters.
cacheIndexNebula
: Likely an identifier for the cache.
expireTime
: Defines the time the cache expires.
A configuration object specifying the request method (GET
) and the accepted response type (application/json
).
The first .then()
block checks the response to ensure the API call was successful. If the message
in the response is not 'success'
, an error is thrown.
If the response is successful, the next .then()
block processes the actual data (CourseData[]
), which is an array of course data.
The array of course data is sorted by the catalog_year
property in descending order. This ensures that the most recent course information is placed at the beginning of the array (index 0
).
It then sets the courseData
state to { state: 'done', data: response[0] }
, where response[0]
is the most recent course data.
Professor Overview API
The code then makes a GET request to the /api/professor
API endpoint using the fetchWithCache
function. This function appears to cache requests to reduce unnecessary API calls. It sends a query with the Professor First
and Last
name as URL parameters (after encoding them for safety), for example, /api/professor?profFirst=John &profLast=Cole
.
The fetchWithCache
function takes in three main arguments:
The URL with query parameters.
cacheIndexNebula
: Likely an identifier for the cache.
expireTime
: Defines the time the cache expires.
A configuration object specifying the request method (GET
) and the accepted response type (application/json
).
The first .then()
block checks the response to ensure the API call was successful. If the message
in the response is not 'success'
, an error is thrown.
The state profData
is then updated to:
{ state: 'done', data: response.data }
if response.data
is defined (indicating that professor data was successfully fetched).
data
: The actual professor data fetched from the API, which is cast to a ProfessorInterface
type.
This part assigns the fetched professor data (response.data
) to the data
property.
The as ProfessorInterface
part is a TypeScript type assertion, which explicitly tells TypeScript to treat response.data
as if it conforms to the ProfessorInterface
type. This ensures the data structure aligns with the expected format for a professor.
OutStanding API’s
combosSearchResultsFetch - Dashboard
fetchGradesData - Dashboard