An FUN API for Open edX
Contents:
This project is in early-development phase, we are still experimenting on it. It is intended to be community-driven, so please, do not hesitate to get in touch if you have any question related to our implementation or design decisions.
Fonzie is an HTTP API over the Open edX project. It has been build to open the way to new tools and interfaces in the Open edX ecosystem.
We choose to design the API first and then propose an implementation with Fonzie. The current state of the API schema is available in API blueprint format; it can be used to start developing a front-end application that will consume Fonzie’s API (take a look at API blueprint tools).
The full documentation is at https://fonzie.readthedocs.org.
The code in this repository is licensed under the AGPL 3.0 unless otherwise noted.
Please see LICENSE.txt
for details.
Contributions are very welcome.
Even though they were written with edx-platform
in mind, the guidelines
should be followed for Open edX code in general.
PR description template should be automatically applied if you are sending PR from github interface; otherwise you can find it it at PULL_REQUEST_TEMPLATE.md
Issue report template should be automatically applied if you are sending it from github UI as well; otherwise you can find it at ISSUE_TEMPLATE.md
Please do not report security issues in public. Please email security@fun-mooc.fr.
Have a question about this repository, or about Open edX in general? Please refer to this list of resources if you need any assistance.
Fonzie is supposed to be installed as a Django application running in an Open edX platform instance. Fonzie has been designed to be integrated with the current Open edX release (Ginkgo at the time of writing). We plan to support the next Open edX release (Hawthorn) in a near future.
Install fonzie and its dependencies in your Open edX installation with pip
:
$ (sudo) pip install fonzie
Once installed, Fonzie needs to be configured as a standard Django application,
i.e. adding fonzie
to your INSTALLED_APPS
and Fonzie’s URLs to your
project’s URLs.
Edit the LMS settings of your Open edX instance (e.g. lms/envs/private.py
) by adding
fonzie
to your INSTALLED_APPS
and configure Django Rest Framework (_aka_
DRF) API versioning support as follows:
# lms/env/private.py
INSTALLED_APPS += (
'fonzie',
)
# Django Rest Framework (aka DRF)
REST_FRAMEWORK.update({
'ALLOWED_VERSIONS': ('1.0', ),
'DEFAULT_VERSION': '1.0',
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning',
})
Add Fonzie’s urls in Open edX LMS’s URLs:
# lms/fonzie_urls.py
from lms.urls import *
urlpatterns += [
# [...]
url(r'^api/', include('fonzie.urls')),
]
Now that we’ve installed and configured Fonzie, it’s time to test that our API
is responding! If we consider that installed Open edX LMS is served from
www.mydomain.com
on the port 8080
, we can use the http
tool (see HTTPie
project) to query the API:
$ http http://www.mydomain.com:8080/api/v1.0/status/version
# http command output
HTTP/1.0 200 OK
Allow: GET, HEAD, OPTIONS
Content-Language: en
Content-Type: application/json
Date: Mon, 28 May 2018 15:37:02 GMT
Server: WSGIServer/0.1 Python/2.7.12
Vary: Accept, Accept-Language, Cookie
X-Frame-Options: ALLOW
{
"version": "0.4.0"
}
Alternatively, you can use curl
:
$ curl http://www.mydomain.com:8080/api/v1.0/status/version
{"version":"0.4.0"}
The output of this command should be a JSON payload containing the running version of Fonzie.
Fonzie’s project has been designed with “container-native development” in mind. In this guide, we will consider that your are familiar with Docker and its ecosystem.
As you might already have expected, we extensively use Docker (17.12+) and Docker compose (1.18+) in our development workflow. So, if you intend to work on Fonzie, please, make sure they are both installed and functional before pursuing this guide.
First things first, to start contributing on the project, you will need to clone Fonzie’s repository and then build the Docker-based development stack with:
# Clone Fonzie's repository
$ git clone git@github.com:openfun/fonzie.git
# Build required containers
$ make bootstrap
The make bootstrap
command will:
edx-platform
Docker image with Fonzie installed and configured,Fonzie’s API should be accessible from: http://localhost:8072/api/v1.0/
We invite you to test the status/version
endpoint to ensure everything went
well:
$ curl http://www.mydomain.com:8080/api/v1.0/status/version
{"version":"0.4.0"}
If you use to work with Django’s development server, you will have the same
experience with a Docker-based development stack: Fonzie is installed in edit
mode and mounted as a volume in the lms
service. Combined with the
development server, the application will be reloaded when the source code
changes.
If your work on Fonzie requires new dependencies, you will need to:
options.install_requires
section of the setup.cfg
file (or
the options.extras_require.[dev,doc,...]
section if it’s a development
dependency),lms
service image via the make build
utility.$ make migrate
fonzie has an assortment of test cases and code quality checks to catch potential problems during development. To run them all in the version of Python you chose for your virtualenv:
$ make validate
To run just the unit tests:
$ make test
To run just the unit tests and check diff coverage
$ make diff_cover
To run just the code quality checks:
$ make lint
To run the unit tests under every supported Python version and the code quality checks:
$ make test-all
To generate and open an HTML report of how much of the code is covered by test cases:
$ make coverage
API status views
API user views
fonzie.views.user.
UserSessionView
(**kwargs)¶Bases: rest_framework.views.APIView
API endpoint to get the authenticated user information.
get
(request, version, format=None)¶Retrieve logged in user, then generate a JWT with a claim containing its username (unique identifier) and its email. The token’s expiration can be changed through the setting ACCESS_TOKEN_LIFETIME (default 5 minutes).
permission_classes
= [<class 'rest_framework.permissions.IsAuthenticated'>]¶fonzie Django application initialization.
Database models for fonzie.
Fonzie, A FUN API for Open edX.