Background

This document captures the conventions to be used for all edX REST APIs. 

Useful reading:

High Level Requirements

Conventions

1. URL Naming

See list of example APIs at the end of this document.

2. Identifying Resources

3. HTTP Verbs

A note on HTTP PATCH

"Plain" HTTP PATCH (RFC 5789) is neutral with respect to content type and only specifies that the request body provide instructions for how to update the resource in question, not the format of those instructions.  Several flavors of PATCH specific to JSON documents have more explicit definition, as noted above.  

In DRF, the default PATCH handling fairly closely resembles what is specified by merge patch, but it does not require (or understand) the "application/merge-patch+json" media type.  In edX REST APIs, if an implementation will use DRF's default PATCH handling, the implementation MUST recognize and accept the merge patch media type; API clients SHOULD use this media type, preferring it to the more typical "application/json" type.

The reason for this stricture is to explicitly leave room for supporting multiple PATCH styles in any given API, should this become desirable, without breaking existing clients.

4. URL Parameters

5. Errors

6. Version

7. Pagination

8. Documentation

9. Discoverability

10. Multiple Formats

11. Authentication

By convention, our REST APIs support the following two authentication schemes:

12. Serialization Conventions

To Be Discussed

Expanding referenced objects

APIs can support expanding related objects, e.g. the team API optionally includes user profile information for each member.  This is preferable to requiring the client to make multiple subsequent AJAX calls.

For example, there can be three levels for a related object (using "username" as an example):

"username": "andya"
"user": {
  "username": "andya",
  "url": "https://openedx.example.com/api/user/v1/accounts/andya"
}
"user": {
  "username": "andya",
  "country": "UK",
  "profile_image": {
    "has_image": True,
    "image_url_full": "http://my-image-storage.net/media/profile_images/123456789_500.jpg",
    "image_url_large": "http://my-image-storage.net/media/profile_images/123456789_120.jpg",
    "image_url_medium": "http://my-image-storage.net/media/profile_images/123456789_50.jpg",
    "image_url_small": "http://my-image-storage.net/media/profile_images/123456789_30.jpg",
  },
  ...
}

By default:

Review Process

APIs must go through a community review process and review by the architecture council before being accepted into the platform. See the Architecture Review Process for the process for gaining approval.

Example APIs

There are a number of existing APIs that you can crib from:

Here are some representative URLs

/api/course/v1/courses/
/api/enrollment/v1/enrollments/
/api/discussion/v1/threads/{thread_id}/