Skip to content

Commit 81b3597

Browse files
committed
docs(en): add api
1 parent 29c13ef commit 81b3597

4 files changed

Lines changed: 1868 additions & 0 deletions

File tree

docs/en/api/caliper.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# About Caliper Endpoints
2+
3+
OpenLRW provides two endpoints that support receipt of event data in IMS Caliper format.
4+
5+
### `/key/caliper`
6+
This endpoint expects only to have your OpenLRW API key passed in the Authorization header. Here is an example:
7+
8+
```javascript
9+
POST /key/caliper HTTP/1.1
10+
Host: localhost:9966
11+
Content-Type: application/json
12+
X-Requested-With: XMLHttpRequest
13+
Authorization: YOUR-API-KEY
14+
Cache-Control: no-cache
15+
16+
{ "sensor": "https://example.edu/sensor/001", "sendTime": "2015-09-15T11:05:01.000Z", "data": [ { "@context": "http://purl.imsglobal.org/ctx/caliper/v1/Context", "@type": "http://purl.imsglobal.org/caliper/v1/Event", "actor": { "@id": "https://example.edu/user/554433", "@type": "http://purl.imsglobal.org/caliper/v1/lis/Person" }, "action": "http://purl.imsglobal.org/vocab/caliper/v1/action#Viewed", "eventTime": "2015-09-15T10:15:00.000Z", "object": { "@id": "https://example.com/viewer/book/34843#epubcfi(/4/3)", "@type": "http://www.idpf.org/epub/vocab/structure/#volume" } } ] }
17+
```
18+
19+
### `/api/caliper`
20+
This endpoint expects you to pass a valid bearer token in the Authorization header. To get a bearer token, first use the login endpoint with your api key and secret as follows:
21+
22+
```javascript
23+
POST /api/auth/login HTTP/1.1
24+
Host: localhost:9966
25+
Content-Type: application/json
26+
X-Requested-With: XMLHttpRequest
27+
Cache-Control: no-cache
28+
29+
{ "username":"YOUR-API-KEY", "password":"YOUR-API-SECRET" }
30+
```
31+
32+
Once you have the token, you can use it as follows:
33+
34+
```javascript
35+
POST /api/caliper HTTP/1.1
36+
Host: localhost:9966
37+
Content-Type: application/json
38+
X-Requested-With: XMLHttpRequest
39+
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI4NmMxMGY5Zi02MDUxLTQxNTEtYTNiYS01ODIwMmZhYWQ4ZjIiLCJzY29wZXMiOlsiUk9MRV9PUkdfQURNSU4iXSwidGVuYW50IjoiNTk2ZTM5N2RhOWY1NjQzYjFmNWFkMDA1IiwiaXNzIjoiaHR0cDovL2V4YW1wbGUuY29tIiwiaWF0IjoxNTAyMjE5MTY3LCJleHAiOjE1MDIyMzM1Njd9.6QvRpoNFe83ulOTIU3UJrAIbZLHCMx7izUwdtirrv5_-cWG5XYxVhi8b5uB5c3pYWBKld1w6y0vx7JPidECBMg
40+
Cache-Control: no-cache
41+
42+
{ "sensor": "https://example.edu/sensor/001", "sendTime": "2015-09-15T11:05:01.000Z", "data": [ { "@context": "http://purl.imsglobal.org/ctx/caliper/v1/Context", "@type": "http://purl.imsglobal.org/caliper/v1/Event", "actor": { "@id": "https://example.edu/user/554433", "@type": "http://purl.imsglobal.org/caliper/v1/lis/Person" }, "action": "http://purl.imsglobal.org/vocab/caliper/v1/action#Viewed", "eventTime": "2015-09-15T10:15:00.000Z", "object": { "@id": "https://example.com/viewer/book/34843#epubcfi(/4/3)", "@type": "http://www.idpf.org/epub/vocab/structure/#volume" } } ] }
43+
44+
```

docs/en/api/examples.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# API usage examples
2+
3+
### Log in
4+
#### Example with Curl
5+
6+
>
7+
8+
```bash
9+
curl -X POST -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
10+
"username": "USERNAME",
11+
"password": "PASSWORD"}' "http://localhost:9966/api/auth/login"
12+
```
13+
14+
15+
#### Example with Python
16+
```python
17+
import requests
18+
import json
19+
20+
response = requests.post("http://localhost:9966/api/auth/login",
21+
headers={'X-Requested-With': 'XMLHttpRequest'},
22+
json={"username": USERNAME, "password": PASSWORD})
23+
response = response.json()
24+
token = response['token']
25+
```

docs/en/api/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# API Reference
2+
3+
Documentation of API endpoints.
4+
5+
* [Routes](routes.md)
6+
* [About Caliper endpoints](caliper.md)
7+
* [API usage examples](examples.md)

0 commit comments

Comments
 (0)