Try out xAPI
There’s a bunch of resources, examples and guides in this section, but we know that developers really love to dive in and have a go. The tasks below will help you to try xAPI in practice. We recommend completing the tasks below in order. Before you complete any of the tasks below, you’ll need to get an LRS.
Get an LRSHow to send your first xAPI statement
You first task is to send a simple xAPI statement. You can do this using any programming language of your choice, but we recommend one of the ones for which we have code libraries. This tutorial includes examples in JavaScript, but we’ll tell you where to look for examples in your language.
1. Get a library
Visit the code libraries page and download the library. Many of the libraries include both source files and build files. You only need the build files.
For JavaScript download the zip file and find tincan.js in the build folder. You don’t need any of the other files.
For other languages, find download links on the code libraries page.
2. Install the library
Follow the installation instructions to include your library in a project. For TinCanJS, create the following simple HTML page. The second set of script tags are where you’ll add your code to send the statement:
<html> <head> <title>Simple TinCanJS Example</title> <script src="tincan.js"></script> <script> //Your code will go here. </script> </head> <body> //You don’t actually need a body for this tutorial. </body> </html>
For other libraries, follow the links below to find installation instructions:
The code libraries not listed above do not currently have installation instructions and we welcome contributions from the community. Good luck!
3. Configure the LRS
You need to configure the library to send the statement to your LRS. Find a set of basic HTTP credentials within your LRS settings. You will need:
- The endpoint. This should end in a / and should not include the word “statements” at the end.
- A username. Also known as a login or key.
- The corresponding password for that username. Also known as a pass or secret.
For TinCanJS, your code will look like this:
var tincan = new TinCan ( { recordStores: [ { endpoint: "https://lrs.example.com/tin-can-endpoint/", username: "key, login or username", password: "secret, password or pass", allowFail: false } ] } );
For other libraries, follow the relevant link on the the code libraries page for an example.
4. Send the statement
Great! You’re now ready to send your first statement. Use the code below for JavaScript. For other libraries, follow the relevant link on the the code libraries page for an example.
tincan.sendStatement( { actor: { mbox: "mailto:your.email.address@example.com" }, verb: { id: "http://adlnet.gov/expapi/verbs/attempted" }, target: { id: "https://experienceapi.com/activities/sending-my-first-statement" } }, function (err, result) { //Handle any errors here. This code just outputs the result to the page. document.write("<pre>"); document.write(JSON.stringify(err, null, 4)); document.write("</pre>"); document.write("<pre>"); document.write(JSON.stringify(result, null, 4)); document.write("</pre>"); } );
Play with xAPI prototypes
You’ve sent your first statement; now it’s time to draw the rest of the owl. Below is a series of challenges to get you digging into the prototypes. For each challenge you’ll have to look at the existing code of one of the prototypes and modify it.
Challenge 1: Golf
The golf prototype is an example of a traditional style e-learning course. We’ve been using the example for years with SCORM, so it was an obvious choice to illustrate xAPI in action. Your challenge is to modify the golf prototype so that it sends an extra statement. You can choose what event you want to track, maybe just add a button on one of the pages. it’s up to you.
Challenge 2: Locator
The locator example takes you on a tour of museums in Nashville, but maybe you don’t live in Nashville! Can you edit the locator to use locations in your area and then try it with some colleagues on your mobile phone? Hint: start with this file.
Challenge 3: Tetris
The Tetris example records all players’ scores in the high scores table, but what about the current player’s personal best? See if you can save that through the State API and display it to the learner when they return for another game. Take a look at how the golf prototype handles bookmarking as a reference.
Challenge 4: Build your own
Have a go at building your own prototype using whatever programming language you’re comfortable with. Share what you make with us and with your colleagues.
Next steps
If you’ve completed all the challenges, then you’re well on your way to developing real projects with xAPI. What are you waiting for? Off you go! Contact us if you have any questions or want to share in interesting story. We’re really excited about what you’re going to do.
Need an LRS?
We offer a range of Learning Record Stores from free simple cloud-based LRS for testing and development, up to a fully fledged Learning Analytics Platform.
Questions? Ask us anything.
At Rustici Software, we help hundreds of people each month with their xAPI questions. Many aren’t sales prospects; they just have questions. We’re happy to help. You can ask us anything ‒ really.