yetanalytics / lrs

Protocols, specifications, and logic for building an xAPI Learning Record Store (LRS) in Clojure(Script).
https://www.yetanalytics.com/lrs
Apache License 2.0
4 stars 1 forks source link
learning-record-store lrs xapi

com.yetanalytics/lrs

CI Clojars Project

Yet Analytics Core LRS Library. Includes protocols and functions used to implement a conformant xAPI Learning Record Store.

Usage

This project is set up to use the clj/clojure executable and deps.edn, with a handy Makefile.

To use the dev profile, which contains all dev/repl/test stuff, use the :dev alias: -A:dev.

Makefile targets of note:

Implementation Notes

Async GET /statements Error Handling

LRS Applications implementing the com.yetanalytics.lrs.protocol/-get-statements-async method return a channel containing results. Since the body is streamed it is not possible to change the status of the request if an error is encountered. Applications can immediately terminate the stream (resulting in a malformed body) by passing :com.yetanalytics.lrs.protocol/async-error to the channel. This is preferable to returning a structurally valid response that is missing data. See this PR for more information.

Statement Attachment Handling & Normalization

PUT/POST /statements

xAPI clients can send statement data with arbitrary file attachments using the multipart/mixed Content-Type per the spec.

Format

Request bodies should be formatted as multipart/mixed per RFC 1341 with the following exceptions:

Normalization

An attachment referenced in an xAPI statement (or substatement) that does not have a fileUrl property must be included at least once in the request body as a part identified by hash. In addition, multiple attachment objects, either in a single statement or across multiple statements in the same request, can refer to the same attachment, as recommended by the spec.

In practice this means that duplicate attachments may be present on the request. lrs will normalize/deduplicate attachments before sending them to implementation code such that every attachment in the list has a distinct hash. See this PR for more information.

Note that requests containing attachments not referenced in statement data will fail with a 400 status.

GET /statements

LRS implementations should return attachments in the same normalized form mentioned above, though this is not checked or enforced by lrs.

Bench Testing

Facilities to bench test any LRS with DATASIM are available. For instance, to bench the in-memory LRS:

$ make run-dev

And in another terminal:

$ clojure -Abench -m com.yetanalytics.lrs.bench http://localhost:8080/xapi -s 1000 -b 100

This will bench the LRS with 1000 statements in POST batches of 100.

License

Copyright © 2018-2021 Yet Analytics Inc.

Licensed under the Apache License, Version 2.0.