/
Course Blocks API

Course Blocks API

This is a detailed design document on the Course Blocks API and how it enables xBlocks on Mobile.

 


Goal

To provide a REST interface for accessing course structure and course blocks for a user.

Background

The edX MOOC platform provides an online learning experience for students via scheduled and self-paced courses.  Educators create courses by either using edX's Studio (a GUI-based course-authoring tool) and/or directly manipulating XML files in edX's published OLX format.  Learners interface with the platform using an LMS (Learning Management System).  The LMS is also used by educators to administer and track live versions of courses.

Course

An edX Course encapsulates the various components that make up a learner's experience in a run of a course (session).  For example, it includes a discussion forum for students and educators to interact, course announcements to update students, a handouts corner for reference information, and other tabular components as customized by the course author.  In the context of this document, these are all peripheral components of a course and not considered further.  Instead, we focus on the courseware, which provides a structural learning pathway, and henceforth simply referred to as the course.

A Course structure is a hierarchical Recursive Composition of primitive and composite objects known as xBlocks. The course structure is a mutable directed acyclic graph (why?) with nodes representing navigational/structural elements (such as sections and subsections), dynamic user-targeted course pathways (such as split test modules), and pedagogical primitives (such as instructional content/videos and student assessments). The course structure is designed to be flexible to support an arbitrary depth of navigation elements and an arbitrary breadth of pathways.

Each edit of the course is uniquely versioned whenever a course author modifies the course structure or any of its components.  A production-level course would typically have anywhere from about 150 to 3000 xBlocks.  A typical MOOC-sized student enrollment could be anywhere from 1,000 to 100,000 students.

xBlock

An xBlock is the basic building block of any edX course.  It controls its own data structure (model), its own HTML rendering (view), and its own business logic (controller).  An xBlock executes in a runtime, which provides common services/utilities, user/request context, and storage.  While the course structure data is primarily stored in a database infrastucture called modulestore, an xBlock's persistence is configured on a field-by-field basis by designating the scope for each of its fields.  Some scopes support user-specific data, which results in different xBlock content for different target users.

An xBlock has a unique identifier known as block-id.  Its instantiation within a context of a course is identified by its usage-id.  A common class of xBlocks have the same defined type (or category) that indicate its common behavior and interface.  Some examples of xBlock types are: "course_info" (shared by Handouts and Announcements), "problem" (shared by all CAPA-based assessments), "video", "chapter" (a.k.a Section), and "sequential" (a.k.a. Subsection).

Access Control

Currently, access control checks are not governed by the xBlock, but by a higher-layer authorization framework in LMS.  A user's access to an xBlock varies depending on (a) their role, (b) their group membership, and (c) their individual settings and history.  Here are a few examples:

  • Role-based Access
    • "Global staff" users can bypass any restrictions on an xBlock in any course.
    • "Course staff" users can bypass any restrictions on an xBlock within their own courses.
    • "Beta users" are exempted from the date restrictions on an xBlock.
    • "Students" cannot access xBlocks marked with visible_to_staff_only.
  • Group Membership Pathways
    • Accessing an xBlock that is restricted to a cohort requires membership in that cohort.
    • Accessing a pathway that is restricted to an A/B test group requires membership in that group.
  • Individual Differentials
    • A "student" that has been given an Individual Due Date Extension on an xBlock can bypass the due date requirement on the xBlock.
    • An xBlock that is gated by a milestone cannot be accessed by a "student" until the student fulfills the required milestone.

Views

Currently, an xBlock controls its own HTML rendering by returning HTML fragments in its implementations of "student_view", "studio_view", and/or "author_view" methods.  These HTML fragments are currently embedded inside LMS and Studio HTML pages and not independently viewed.

Requirements

Technical Requirements

Here are the basic technical requirements:

  • FUTURE (for Course Navigation): Although the course structure supports an arbitrary navigational depth, the client UI should be able to enforce a maximum navigational depth.  This allows for a clear and consistent user experience through the course, if/when the UX chooses to do so.
  • The payload needs to be user-specific, while honoring roles, group pathways, and individual differentials.
  • It should be possible to delegate the rendering of an xBlock to the client by providing the xBlock's raw data (e.g., in JSON).  This allows us to support:

    • a user experience that is native to the device.

    • a different design of the xBlock's (student) view.
  • It should be possible to render the student view of an individual xBlock without the envelope of the LMS chrome.
  • APIs should follow the edX REST API Conventions.
  • The response payload for a Course Blocks API should be consistent with the existing Course Structure API that was reviewed and approved by the Architecture Council.

Non-Requirements

  • Generalizing the endpoint to allow the consumer to request the value of any arbitrary field of an xBlock.

Use Cases

1. Mobile Apps

The initial primary clients of these new API endpoints are the edX Mobile apps as we embark on supporting interactive assessments on iOS and Android devices.  Our initial goals are to evolve the mobile app's simple-to-use video player to provide context and interactivity by adding further course structural context and basic assessment support.

The currently proposed UI requires presenting the following elements to the user:

    • A course dashboard with links to various components of the course, including forums, announcements, handouts, and the courseware.
    • A course outline page listing the 2 top-level navigational components (Sections and Subsections) of the course structure.
    • A course subsection page showing the 3rd navigational component (Unit) and all primitive xBlocks within each Unit.
    • Aggregate information including (a) the total count of videos in a Section of the course and (b) whether a Section contains graded components.
    • A web-hosted rendering of an individual primitive xBlock through a mobile WebView runtime on the device.
    • A native rendering of all xBlocks of type video.

 

      

2. Custom LMS Front-End

We can also imagine an ecosystem with other/extended front-end LMS subsystems that are optimized for different user experiences.  For example:

    • An open source contributor creates a native implementation of an assessment type, which exploits the device's accelerometer to engage the user. 
    • An LMS view chooses to display the course blocks vertically in a Continuous Scrolling pattern.
    • An Adaptive Learning application that dynamically adjusts the student's navigation through the course.

3. Displaying Individual xBlocks

The capability to render an individual xBlock can enable many different features.  For example:

    • An Adaptive Learning tool that refreshes a student's memory by presenting the same assessment at a future date given aggregate analytical data on memory loss.
    • A Flashcard application that renders individual xBlocks of a new type called flashcard.

4. Reuse and Performance Optimization for other LMS Features

Assuming that the new endpoints have been optimized for performance, they can be reused for other features in the edX Platform.  For example, the Bookmarks feature may want to quickly query information about a user's perception of an xBlock.

Related APIs

  • The Mobile Video Outlines API will be deprecated by this new API.  The current one is limited to returning only video modules in a course and was designed specifically for mobile's use.  Additionally, it intrusively retrieves the video module's data by directly accessing the video's fields.

  • The existing Course Structure API is an instructor-facing API and not intended for use by a student-facing client.  It requires course staff access and returns all xBlocks in the course, disregarding any role-based, group-pathway, or individual differentiation.  This proposal keeps this endpoint as is, but proposes renaming it as described below.

API Design

This section describes the overall design approach for the following set of APIs:

  1. A new generic Courses API as a residence for course-related endpoints.
  2. A new Course Blocks API that provides necessary data for creating courseware navigation and interaction.  This API is parameterized to support both user-specific and not-user-specific responses.
  3. A new xBlock URL that supports rendering of an individual xBlock. 

Generic APIs versus Mobile-specific APIs

First, a note on our overall approach for designing endpoints used by our mobile apps.  As we design APIs for mobile consumption, we try to abide by the following design constraints:

  1. Authentication: The API must support OAuth2 as an authentication mechanism as the mobile apps use the Bearer authentication scheme to transmit the openedX-issued OAuth2 access token.
  2. Authorization: The API must enforce server-side access control checks for all data access.
  3. Client/server division of labor: In general, business logic should be centralized on the server thereby allowing thinner clients and future maintainability.
  4. Performance:
    • Response Time: The 95% response time must be within 2 seconds (at most) for a healthy server and a responsive user experience.
    • Round Trips: A responsive global access to the API requires optimizing network latency by minimizing the number of API round trips.  For example, displaying a single screen on the mobile app should not require more than a single API call.  As a trade-off with payload size, pre-fetching and client-side caching of the data is also considered.
    • Payload Size: In addition to minimizing round trips, the size of the payload should be frugal to optimize network and cellular bandwidth.  So we design APIs that allow parameterizing which fields are returned.

While critical to the mobile experience, the above constraints can also be met by generic APIs that can be used by other (non-mobile) clients.  So going forward, we aim at creating generic APIs that can be consumed by both mobile and non-mobile clients.  However, if additional customized optimization is needed that is inherently mobile-specific, then we will implement a mobile-specific API as a layer above the generic one.

Courses API

 Having a multitude of endpoints and API resources for each type of data for a course can be both hard to maintain and difficult to understand for API consumers.  Instead, we have designed a top-level resource for courses, as follows.  The API is now documented on read-the-docs.

Note: The current Course Structure API would be renamed as below.

endpointdescriptionparametersresponse info

course catalog
api/courses/v1/courses/
 


Status: Implemented

returns a list of courses and their metadata

use cases:

  • course search page, course catalog - by accessing the endpoint as a non-privileged/anonymous user or passing in target user's username as a parameter
  • external privileged system enumerating through courses - by accessing the endpoint as a privileged user

note: for a list of enrolled courses, the enrollment API should be used instead.

  • user for a user-specific data
  • sort by date, name, org, etc.
  • paging
  • filters: mobile_only, category, etc.
  • if no user parameter is given, it lists all possible courses that the requested user can view.
  • if a user parameter is given, it lists only those courses that the target user can view.
  • each course's data response is as described in the course meta data endpoint below.

course metadata
api/courses/v1/courses/<course_id>


Status: Implemented

returns the meta data for the requested course

use cases: "course profile" information, like for a post on a social media page

user

id
name
start
end
image_url
updates_url
handouts_url
blocks_url
lms_web_url
about_url (drupal site)

course blocks
/api/courses/v1/blocks/<root_block_usage_id>/
?depth=all

or

/api/courses/v1/blocks/?course_id=<course_id>


Status: Implemented 

returns the blocks in the course starting at the requested root.

use cases: for accessing course content

user-specific
user=anjali

user-specific, mobile fields
user=anjali,
&fields=graded,format,multi_device,
&block_counts=video,
&student_view_data=video,
&student_view_data.video=mobile_low

all blocks for insights
fields=graded,format

 

FUTURE parameters
type - filter by block type

views other than student_view
A dictionary of blocks, with the key being the block’s usage_id and the value being the block’s data (as defined in the block data endpoint below).

course block data 
/api/courses/v1/blocks/<usage_id>/


Status: Not yet implemented

returns the data for the requested blocksame as for the course blocks endpoint

id
type
display_name
children
lms_web_url
olx_data
student_view_url
student_view_data

plus, requested fields that are supported, such as:

student_view_multi_device
graded
format
block_counts

course navigation
 

 

Status: Not approved

We will have FUTURE support for course navigation once it is designed.

returns the navigation information of the course starting at the requested root

use cases: for displaying the course hierarchy in a li