Codearena is a tool to aid in accessibility in the classroom.
Download the project from courseweb. It is a zip file consisting of two folders: codearena-api and codearena-client. Codearena-api is the Erlang server and codearena-client is the web interface.
This application uses CouchDB to store the code arenas. To set this up, create a database called arenas.
- couchdb (installed and running)
- web browser
- Go to http://localhost:5984/_utils, or wherever couchdb is running on your machine.
- Create a new database called arenas.
This completes the set up for the database. The UI and API will work in conjunction to add/delete/update documents in this database, and the state of these records can be viewed here at any time.
This is a REST API that I set up using gen_tcp. It receives requests from a browser or other HTTP client, such as postman. It serves as a proxy to the database, querying and then returning responses back to the HTTP client.
- Open the codearena-api folder (from the project .zip) in Eclipse. This is where you’ll start the API.
- Right-click on api.erl and then Run As > Erlang application. This should open the console in Eclipse where you can enter the commands.
- Start the server by typing
api:start(4000).
. You could really start it on any port, but if you want to use the web interface, use4000
.
This concludes the API set up. I do have the API set up to log many of the requests to the console to see what the data looks like, so check back here to see what’s going on at any time.
This step involves setting up a web interface that allows you to interact with the API in a usable way. It does involve a few dependencies that you might need to install, depending on your existing environment. If that’s not something you want to do, then the API is available to interact with via an HTTP client such as Postman, or an HTTP browser extension of your choice. If that’s what you want to do, skip to the next section labeled Interacting with the API through an HTTP Client below.
The following need to be present on your system:
- Open a terminal and go to the codearena-client folder inside the extracted project folder
- Run
yarn
. This will pull in all of the dependencies for the UI project to run. - Yarn also contains a local http server that we'll use. To start this, run
yarn dev
. This will do a bunch of stuff and then printwebpack: Compiled successfully.
. Once this is displayed, open a browser and go tolocalhost:8080
. You should see the site displayed.
- Click the "Stream" button. This means that as you type, the site will periodically push your code contents to the server, which inserts it into the database.
- Open another browser window and navigate to the same URL where you're broadcasting. This is a student node. On initial page load, it will get the most up-to-date code by the arenaId (the URL param).
- On the professor page, begin typing again. In the student page, you'll see it's not updating. In order to see the live-coding, click the "Watch" button. Now your browser will poll for updates.
- As a professor, to stop streaming, click the "Stop Streaming" button. Now the students will no longer receive the code you're typing.
- As a student, you can stop watching by clicking the "Stop Watching" button. You will no longer receive live updates.
At any point, you can save your progress by clicking the "Save" button.
- Type some stuff.
- Click "Save".
- Click "Delete" button.
If you’ve decided to skip the UI set up (which you shouldn’t, because I worked hard on that!), then here are some end points that you can hit to see that my API does work.
- HTTP client (ex. Postman, browser extensions that do HTTP requests, cURL, etc)
- TCP Server from earlier step is running on Port 4000.
- Couchdb is up and running and you've made the arenas database.
GET /api/arena
GET /api/arena/{arenaId}
- arenaId: maps to couchdb’s “_id” field. An arena with this _id must already exist in the database.
{
"codeString": "some string",
"_id": "123",
"_rev": "456"
}
PUT /api/arena/{arenaId}
- arenaId: maps to couchdb’s “_id” field. This can be whatever you want it to be but must be unique in the database.
{
"codeString": "some string here"
}
{
"ok": true,
"id": 123,
"rev": 456
}
PUT /api/arena/{arenaId}
- arenaId: maps to couchdb’s “_id” field. An arena with this _id must already exist in the database.
You must know the latest revision ID of the document in order to update it. This prevents conflicts.
{
"_rev": "456",
"codeString": "an updated string"
}
The revision ID will update to show it has been changed.
{
"ok": true,
"id": 123,
"rev": 789
}
DELETE /api/arena/{arenaId}?rev={revisionId}
- arenaId: maps to couchdb’s “_id” field. An arena with this _id must already exist in the database.
- revisionId: maps to couchdb's "_rev" field. An arena with this _rev must already exist in the database.
The revision ID will update to show it has been changed, even though we made a DELETE
request. Couchdb documents aren't ever completely deleted - if you try to query for a deleted document, it will tell you it's been deleted.
{
"ok": true,
"id": 123,
"rev": 910
}