Skip to main content

REST API

REST API-related functions are written in features/api directory.

Assignments and Quizzes can be fetched from Sakai REST API by fetchAssignment() and fetchQuiz() function respectively.

Implementation

For example fetchAssignment() takes Course object as parameter and uses Course.id to send GET request to Sakai REST API.

Sakai REST API provides two ways to get Assignments:

  • Get Assignments for each course site
    • [GET] /direct/assignment/site/<courseID>.json
  • Get all Assignments of all course sites

For complete REST API detail, please refer to https://<Sakai LMS>/direct/assignment/describe for documentation.

features/api/fetch.ts
export const fetchAssignment = (course: Course): Promise<Assignment> => {
const queryURL = getBaseURL() + "/direct/assignment/site/" + course.id + ".json";
return new Promise((resolve, reject) => {
fetch(queryURL, { cache: "no-cache" })
.then(async (response) => {
if (response.ok) {
const data = await response.json();
const assignmentEntries = decodeAssignmentFromAPI(data);
resolve(new Assignment(course, assignmentEntries, false));
} else {
reject(`Request failed: ${response.status}`);
}
})
.catch((err) => console.error(err)); // Error: Request failed: 404
});
};