Skip to content

Commit

Permalink
APIv3: wrapping all results in JSON (nightscout#6703)
Browse files Browse the repository at this point in the history
* APIv3: isolating documents from tests (not allowing clashes of calculated identifiers)

* removing unused async keyword

* fixing api v3 swagger and moving it to /api3-docs

* APIv3: adding cachedCollection stub of cachedCollection storage implementation

* APIv3: mongo cachedCollection storage implementation

* APIv3: testing and debugging cache updates

* APIv3: more testing on cache updates

* APIv3: fixing bad async functions

* APIv3: finishing cache invalidation tests

* APIv3: wrapping VERSION result

* APIv3: wrapping STATUS result

* APIv3: wrapping DELETE result

* APIv3: wrapping READ result + partially SEARCH and HISTORY

* APIv3: wrapping CREATE result

* APIv3: wrapping UPDATE + PATCH result

* APIv3: wrapping LAST MODIFIED result

* APIv3: updating swagger doc

* APIv3: updating tutorial.md

* APIv3: tuning tests

* APIv3: merge dev

Co-authored-by: Petr Ondrusek <[email protected]>
Co-authored-by: Petr Ondrůšek <[email protected]>
Co-authored-by: Sulka Haro <[email protected]>
  • Loading branch information
4 people authored and Alex Ovcinnikov committed Nov 6, 2021
1 parent e052420 commit 29b3810
Show file tree
Hide file tree
Showing 28 changed files with 1,543 additions and 567 deletions.
5 changes: 3 additions & 2 deletions lib/api3/const.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"API3_VERSION": "3.0.0-alpha",
"API3_VERSION": "3.0.2-alpha",
"API3_SECURITY_ENABLE": true,
"API3_TIME_SKEW_TOLERANCE": 5,
"API3_DEDUP_FALLBACK_ENABLED": true,
Expand Down Expand Up @@ -41,6 +41,7 @@
"HTTP_401_MISSING_OR_BAD_TOKEN": "Missing or bad access token or JWT",
"HTTP_403_MISSING_PERMISSION": "Missing permission {0}",
"HTTP_403_NOT_USING_HTTPS": "Not using SSL/TLS",
"HTTP_404_BAD_OPERATION": "Bad operation or collection",
"HTTP_406_UNSUPPORTED_FORMAT": "Unsupported output format requested",
"HTTP_422_READONLY_MODIFICATION": "Trying to modify read-only document",
"HTTP_500_INTERNAL_ERROR": "Internal Server Error",
Expand All @@ -52,4 +53,4 @@
"MIN_TIMESTAMP": 946684800000,
"MIN_UTC_OFFSET": -1440,
"MAX_UTC_OFFSET": 1440
}
}
53 changes: 28 additions & 25 deletions lib/api3/doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,34 @@ The server replies with `406 Not Acceptable` HTTP status in case of not supporte

Default content type is JSON, output can look like this:

```
[
{
"type":"sgv",
"sgv":"171",
"dateString":"2014-07-19T02:44:15.000-07:00",
"date":1405763055000,
"device":"dexcom",
"direction":"Flat",
"identifier":"5c5a2404e0196f4d3d9a718a",
"srvModified":1405763055000,
"srvCreated":1405763055000
},
{
"type":"sgv",
"sgv":"176",
"dateString":"2014-07-19T03:09:15.000-07:00",
"date":1405764555000,
"device":"dexcom",
"direction":"Flat",
"identifier":"5c5a2404e0196f4d3d9a7187",
"srvModified":1405764555000,
"srvCreated":1405764555000
}
]
```json
{
"status": 200,
"result": [
{
"type": "sgv",
"sgv": "171",
"dateString": "2014-07-19T02:44:15.000-07:00",
"date": 1405763055000,
"device": "dexcom",
"direction": "Flat",
"identifier": "5c5a2404e0196f4d3d9a718a",
"srvModified": 1405763055000,
"srvCreated": 1405763055000
},
{
"type": "sgv",
"sgv": "176",
"dateString": "2014-07-19T03:09:15.000-07:00",
"date": 1405764555000,
"device": "dexcom",
"direction": "Flat",
"identifier": "5c5a2404e0196f4d3d9a7187",
"srvModified": 1405764555000,
"srvCreated": 1405764555000
}
]
}
```

### XML
Expand Down
240 changes: 134 additions & 106 deletions lib/api3/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ request('https://nsapiv3.herokuapp.com/api/v3/version',
(error, response, body) => console.log(body));
```
Sample result:
```javascript
{
"version":"0.12.2",
"apiVersion":"3.0.0-alpha",
"srvDate":1564386001772,
"storage":{
"storage":"mongodb",
"version":"3.6.12"
}
```json
{
"status": 200,
"result": {
"version": "14.1.0",
"apiVersion": "3.0.2-alpha",
"srvDate": 1609402081548,
"storage": {
"storage": "mongodb",
"version": "4.2.11"
}
}
}
```

Expand All @@ -50,22 +53,25 @@ request(`https://nsapiv3.herokuapp.com/api/v3/status?${auth}`,
(error, response, body) => console.log(body));
```
Sample result:
```javascript
{
"version":"0.12.2",
"apiVersion":"3.0.0-alpha",
"srvDate":1564391740738,
"storage":{
"storage":"mongodb",
"version":"3.6.12"
},
"apiPermissions":{
"devicestatus":"crud",
"entries":"crud",
"food":"crud",
"profile":"crud",
"settings":"crud",
"treatments":"crud"
```json
{
"status": 200,
"result": {
"version": "14.1.0",
"apiVersion": "3.0.2-alpha",
"srvDate": 1609427571833,
"storage": {
"storage": "mongodb",
"version": "4.2.11"
},
"apiPermissions": {
"devicestatus": "crud",
"entries": "crud",
"food": "crud",
"profile": "crud",
"settings": "crud",
"treatments": "crud"
}
}
}
```
Expand All @@ -86,24 +92,27 @@ request(`https://nsapiv3.herokuapp.com/api/v3/entries?${auth}&sort$desc=date&lim
(error, response, body) => console.log(body));
```
Sample result:
```
[
{
"dateString":"2019-07-30T02:24:50.434+0200",
"sgv":115,
"direction":"FortyFiveDown"
},
{
"dateString":"2019-07-30T02:19:50.374+0200",
"sgv":121,
"direction":"FortyFiveDown"
},
{
"dateString":"2019-07-30T02:14:50.450+0200",
"sgv":129,
"direction":"FortyFiveDown"
}
]
```json
{
"status": 200,
"result": [
{
"dateString": "2019-07-30T02:24:50.434+0200",
"sgv": 115,
"direction": "FortyFiveDown"
},
{
"dateString": "2019-07-30T02:19:50.374+0200",
"sgv": 121,
"direction": "FortyFiveDown"
},
{
"dateString": "2019-07-30T02:14:50.450+0200",
"sgv": 129,
"direction": "FortyFiveDown"
}
]
}
```


Expand All @@ -129,11 +138,15 @@ request({
json: true,
url: `https://nsapiv3.herokuapp.com/api/v3/treatments?${auth}`
},
(error, response, body) => console.log(response.headers.location));
(error, response, body) => console.log(body));
```
Sample result:
```
/api/v3/treatments/95e1a6e3-1146-5d6a-a3f1-41567cae0895
```json
{
"status": 201,
"identifier": "95e1a6e3-1146-5d6a-a3f1-41567cae0895",
"lastModified": 1564591511711
}
```


Expand All @@ -152,19 +165,22 @@ request(`https://nsapiv3.herokuapp.com/api/v3/treatments/${identifier}?${auth}`,
(error, response, body) => console.log(body));
```
Sample result:
```
{
"date":1564591511232,
"app":"AndroidAPS",
"device":"Samsung XCover 4-861536030196001",
"eventType":"Correction Bolus",
"insulin":0.3,
"identifier":"95e1a6e3-1146-5d6a-a3f1-41567cae0895",
"utcOffset":0,
"created_at":"2019-07-31T16:45:11.232Z",
"srvModified":1564591627732,
"srvCreated":1564591511711,
"subject":"test-admin"
```json
{
"status": 200,
"result": {
"date": 1564591511232,
"app": "AndroidAPS",
"device": "Samsung XCover 4-861536030196001",
"eventType": "Correction Bolus",
"insulin": 0.3,
"identifier": "95e1a6e3-1146-5d6a-a3f1-41567cae0895",
"utcOffset": 0,
"created_at": "2019-07-31T16:45:11.232Z",
"srvModified": 1564591627732,
"srvCreated": 1564591511711,
"subject": "test-admin"
}
}
```

Expand All @@ -183,14 +199,17 @@ request(`https://nsapiv3.herokuapp.com/api/v3/lastModified?${auth}`,
(error, response, body) => console.log(body));
```
Sample result:
```javascript
```json
{
"srvDate":1564591783202,
"collections":{
"devicestatus":1564591490074,
"entries":1564591486801,
"profile":1548524042744,
"treatments":1564591627732
"status": 200,
"result": {
"srvDate": 1564591783202,
"collections": {
"devicestatus": 1564591490074,
"entries": 1564591486801,
"profile": 1548524042744,
"treatments": 1564591627732
}
}
}
```
Expand Down Expand Up @@ -220,11 +239,13 @@ request({
json: true,
url: `https://nsapiv3.herokuapp.com/api/v3/treatments/${identifier}?${auth}`
},
(error, response, body) => console.log(response.statusCode));
(error, response, body) => console.log(body));
```
Sample result:
```
204
```json
{
"status": 200
}
```


Expand All @@ -248,11 +269,13 @@ request({
json: true,
url: `https://nsapiv3.herokuapp.com/api/v3/treatments/${identifier}?${auth}`
},
(error, response, body) => console.log(response.statusCode));
(error, response, body) => console.log(body));
```
Sample result:
```
204
```json
{
"status": 200
}
```


Expand All @@ -271,11 +294,13 @@ request({
method: 'delete',
url: `https://nsapiv3.herokuapp.com/api/v3/treatments/${identifier}?${auth}`
},
(error, response, body) => console.log(response.statusCode));
(error, response, body) => console.log(body));
```
Sample result:
```
204
```json
{
"status": 200
}
```


Expand All @@ -294,36 +319,39 @@ request(`https://nsapiv3.herokuapp.com/api/v3/treatments/history/${lastModified}
(error, response, body) => console.log(response.body));
```
Sample result:
```
[
{
"date":1564521267421,
"app":"AndroidAPS",
"device":"Samsung XCover 4-861536030196001",
"eventType":"Correction Bolus",
"insulin":0.5,
"utcOffset":0,
"created_at":"2019-07-30T21:14:27.421Z",
"identifier":"95e1a6e3-1146-5d6a-a3f1-41567cae0895",
"srvModified":1564592440416,
"srvCreated":1564592334853,
"subject":"test-admin",
"modifiedBy":"test-admin",
"isValid":false
},
{
"date":1564592545299,
"app":"AndroidAPS",
"device":"Samsung XCover 4-861536030196001",
"eventType":"Snack Bolus",
"carbs":10,
"identifier":"267c43c2-f629-5191-a542-4f410c69e486",
"utcOffset":0,
"created_at":"2019-07-31T17:02:25.299Z",
"srvModified":1564592545781,
"srvCreated":1564592545781,
"subject":"test-admin"
}
]
```json
{
"status": 200,
"result": [
{
"date": 1564521267421,
"app": "AndroidAPS",
"device": "Samsung XCover 4-861536030196001",
"eventType": "Correction Bolus",
"insulin": 0.5,
"utcOffset": 0,
"created_at": "2019-07-30T21:14:27.421Z",
"identifier": "95e1a6e3-1146-5d6a-a3f1-41567cae0895",
"srvModified": 1564592440416,
"srvCreated": 1564592334853,
"subject": "test-admin",
"modifiedBy": "test-admin",
"isValid": false
},
{
"date": 1564592545299,
"app": "AndroidAPS",
"device": "Samsung XCover 4-861536030196001",
"eventType": "Snack Bolus",
"carbs": 10,
"identifier": "267c43c2-f629-5191-a542-4f410c69e486",
"utcOffset": 0,
"created_at": "2019-07-31T17:02:25.299Z",
"srvModified": 1564592545781,
"srvCreated": 1564592545781,
"subject": "test-admin"
}
]
}
```
Notice the `"isValid":false` field marking the deletion of the document.
Loading

0 comments on commit 29b3810

Please sign in to comment.