Skip to content

Commit afe3e29

Browse files
committed
Add student API documentation
1 parent c56b889 commit afe3e29

File tree

3 files changed

+240
-9
lines changed

3 files changed

+240
-9
lines changed

source/index.html.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ search: true
1616

1717
*Note: API is still a work in progress.*
1818

19+
For the students, view <a href="/student_api">the student api</a>
20+
1921
API provides an alternative way of interacting with Submitty. It facilitates testing, helps system administrators to modify resources and enables users to create customized frontends.
2022

2123
Note that as we rely on the Authorization header information to authenticate users, please make sure that you have a correct Apache configuration file as specified in [Installation Version Notes: v19.06.02](https://submitty.org/sysadmin/version_notes/v19.06.02).

source/student_api/index.html.md

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
---
2+
title: Submitty API Reference
3+
4+
language_tabs: # must be one of https://git.io/vQNgJ
5+
- shell
6+
7+
toc_footers:
8+
- <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a>
9+
10+
includes:
11+
12+
search: true
13+
---
14+
15+
# Introduction
16+
17+
*Note: Student API is still a work in progress.*
18+
19+
API provides an alternative way of interacting with Submitty. This is intended for students to be able to interact with Submitty without using the web UI.
20+
21+
__*Note: All student requests require a parameter of 'user_id' for verification.*__
22+
23+
<aside class="warning">
24+
The API is not formally versioned at this time, and its endpoints and their responses may change
25+
without warning. Use at your own risk!
26+
</aside>
27+
28+
# Requests
29+
30+
Submitty supports requests using the following two `content-types`:
31+
32+
* application/json
33+
* application/x-www-form-urlencoded
34+
35+
while anything involving files should use:
36+
37+
* multipart/form-data
38+
39+
All endpoints use the `/student_api` path off the base Submitty URL, followed by the specific endpoint
40+
for the API in question.
41+
42+
# Responses
43+
44+
> Example of a `success` JSON response:
45+
46+
```json
47+
{
48+
"status": "success",
49+
"data": null
50+
}
51+
```
52+
53+
> Example of a `fail` JSON response:
54+
55+
```json
56+
{
57+
"status": "fail",
58+
"message": "Gradeable does not exist."
59+
}
60+
```
61+
62+
All API responses will be returned as `application/json` and conform to a modified
63+
version of the [JSend specification](https://labs.omniti.com/labs/jsend). A response
64+
returned from the server is expected to be one of the following three response types.
65+
66+
| Type | Description | Required Keys | Optional Keys |
67+
|---------|-----------------------------------------------------------------------------------------------------|----------------|---------------|
68+
| success | All went well, and (usually) some data was returned | status, data | |
69+
| fail | There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied | status, message | data |
70+
| error | An error occurred in processing the request, i.e. an exception was thrown | status, message | data, code |
71+
72+
# Authentication
73+
74+
```shell
75+
# With shell, you can just pass the correct header with each request
76+
curl "student_api_endpoint_here"
77+
-H "Authorization: my_token"
78+
```
79+
80+
> Make sure to replace `my_token` with your API token, or the API will return JSON like this:
81+
82+
```json
83+
{
84+
"status": "fail",
85+
"message": "Unauthenticated access. Please log in."
86+
}
87+
```
88+
89+
Submitty uses [JSON Web Tokens](https://jwt.io/) to allow access to the API. You can obtain your API token through the following endpoint.
90+
91+
Kittn expects for the API token to be included in all API requests to the server in a header that looks like the following:
92+
93+
`Authorization: my_token`
94+
95+
<aside class="notice">
96+
You must replace <code>my_token</code> with your personal API token.
97+
</aside>
98+
99+
## Get Token
100+
101+
```shell
102+
curl -X POST \
103+
<base_url>/student_api/token \
104+
-F user_id=student \
105+
-F password=student
106+
```
107+
108+
> The above command returns JSON structured like this:
109+
110+
```json
111+
{
112+
"status": "success",
113+
"data": {
114+
"token": "a long string"
115+
}
116+
}
117+
```
118+
119+
Note that every time you request a new token, the previous token will be invalidated.
120+
121+
### HTTP Request
122+
123+
`POST /student_api/token`
124+
125+
### Parameters
126+
127+
Parameter | Description
128+
--------- | -----------
129+
user_id | User's unique ID
130+
password | User's password
131+
132+
## Invalidate Token
133+
134+
```shell
135+
curl -X POST \
136+
<base_url>/student_api/token/invalidate \
137+
-F user_id=student \
138+
-F password=student
139+
```
140+
141+
The endpoint invalidates the token you requested before.
142+
143+
### HTTP Request
144+
145+
`POST /student_api/token/invalidate`
146+
147+
### Parameters
148+
149+
Parameter | Description
150+
--------- | -----------
151+
user_id | User's unique ID
152+
password | User's password
153+
154+
# Gradeables
155+
156+
## Get score
157+
158+
```shell
159+
curl -X GET \
160+
<base_url>/student_api/<term>/<course>/gradeable/<gradeable_id>/score?user_id=<user_id>
161+
162+
```
163+
> Possible responses:
164+
165+
```json
166+
{
167+
"status": "success",
168+
"data": {
169+
"score": 0
170+
}
171+
}
172+
```
173+
```json
174+
{
175+
"status": "fail",
176+
"message": "Gradeable does not exist"
177+
}
178+
```
179+
180+
The endpoint returns the score of an autograded gradeable.
181+
182+
### HTTP Request
183+
184+
`GET /student_api/<term>/<course>/gradeable/<gradeable_id>/score?user_id=<user_id>`
185+
186+
### Parameters
187+
188+
Parameter | Description
189+
--------- | -----------
190+
user_id | User's unique ID
191+
192+
## Submit VCS Gradeable
193+
194+
```shell
195+
curl -X POST \
196+
<base_url>/student_api/<term>/<course>/gradeable/<gradeable_id>/upload\
197+
-F user_id=student \
198+
-F vcs_checkout=true
199+
```
200+
> Possible responses:
201+
202+
```json
203+
{
204+
"status": "success",
205+
"data": "Successfully uploaded version {#} for {Gradeable Title}"
206+
}
207+
```
208+
```json
209+
{
210+
"status": "fail",
211+
"message": "Invalid gradeable id '{Gradeable ID}'"
212+
}
213+
```
214+
```json
215+
{
216+
"status": "fail",
217+
"message": "Student API for upload only supports VCS gradeables"
218+
}
219+
```
220+
221+
222+
The endpoint requests for a VCS gradeable to be submitted.
223+
224+
### HTTP Request
225+
226+
`GET /student_api/<term>/<course>/gradeable/<gradeable_id>/upload`
227+
228+
### Parameters
229+
230+
Parameter | Description
231+
--------- | -----------
232+
user_id | User's unique ID
233+

source/stylesheets/screen.css.scss

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@import 'normalize';
33
@import 'variables';
44
@import 'icon-font';
5-
// @import 'rtl'; // uncomment to switch to RTL format
5+
/*@import 'rtl'; // uncomment to switch to RTL format*/
66

77
/*
88
Copyright 2008-2013 Concur Technologies, Inc.
@@ -33,7 +33,7 @@ html, body {
3333
@extend %default-font;
3434
background-color: $main-bg;
3535
height: 100%;
36-
-webkit-text-size-adjust: none; /* Never autoresize text */
36+
-webkit-text-size-adjust: none;
3737
}
3838

3939
////////////////////////////////////////////////////////////////////////////////
@@ -62,7 +62,6 @@ html, body {
6262
font-size: 13px;
6363
font-weight: bold;
6464

65-
// language selector for mobile devices
6665
.lang-selector {
6766
display: none;
6867
a {
@@ -71,7 +70,6 @@ html, body {
7170
}
7271
}
7372

74-
// This is the logo at the top of the ToC
7573
.logo {
7674
display: block;
7775
max-width: 100%;
@@ -91,7 +89,7 @@ html, body {
9189
width: $nav-width - ($nav-padding*2);
9290
outline: none;
9391
color: $nav-text;
94-
border-radius: 0; /* ios has a default border radius */
92+
border-radius: 0;
9593
}
9694

9795
&:before {
@@ -220,7 +218,7 @@ html, body {
220218
transform: rotate(-90deg) translate(-100%, 0);
221219
border-radius: 0 0 0 5px;
222220
}
223-
padding: 0 1.5em 5em 0; // increase touch size area
221+
padding: 0 1.5em 5em 0;
224222
display: none;
225223
position: fixed;
226224
top: 0;
@@ -254,7 +252,7 @@ html, body {
254252
background-color: $main-bg;
255253
min-height: 100%;
256254

257-
padding-bottom: 1px; // prevent margin overflow
255+
padding-bottom: 1px;
258256

259257
// The dark box is what gives the code samples their dark background.
260258
// It sits essentially under the actual content block, which has a
@@ -314,9 +312,7 @@ html, body {
314312
// This is all the stuff with the light background in the left half of the page
315313

316314
.content {
317-
// fixes webkit rendering bug for some: see #538
318315
-webkit-transform: translateZ(0);
319-
// to place content above the dark box
320316
position: relative;
321317
z-index: 30;
322318

0 commit comments

Comments
 (0)