From a2e054c672b5af7d42184ad0264fa19fb3157f65 Mon Sep 17 00:00:00 2001 From: korelstar Date: Sat, 13 Mar 2021 09:44:33 +0100 Subject: [PATCH] API: ETag/If-None-Match for Get single note --- docs/api/v1.md | 2 ++ lib/Controller/NotesApiController.php | 5 ++++- package-lock.json | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/api/v1.md b/docs/api/v1.md index 27977fcac..f59befa27 100644 --- a/docs/api/v1.md +++ b/docs/api/v1.md @@ -91,9 +91,11 @@ No valid authentication credentials supplied. | Parameter | Type | Description | |:------|:-----|:-----| | `id` | integer, required (path) | ID of the note to query. | +| `If-None-Match` | HTTP header, optional | Use this in order to reduce transferred data size (see [HTTP ETag](https://en.wikipedia.org/wiki/HTTP_ETag)). You should use the value from the note's attribute `etag` or from the last request's HTTP response header `ETag`. | 1.2 | #### Response ##### 200 OK +- **HTTP Header**: `ETag` (see [HTTP ETag](https://en.wikipedia.org/wiki/HTTP_ETag)). The value is identical to the note's attribute `etag` (see section [Note attributes](#note-attributes)). - **Body**: note (see section [Note attributes](#note-attributes)), example: ```js { diff --git a/lib/Controller/NotesApiController.php b/lib/Controller/NotesApiController.php index 30928eaee..9c27ad112 100644 --- a/lib/Controller/NotesApiController.php +++ b/lib/Controller/NotesApiController.php @@ -68,7 +68,10 @@ public function get(int $id, string $exclude = '') : JSONResponse { return $this->helper->handleErrorResponse(function () use ($id, $exclude) { $exclude = explode(',', $exclude); $note = $this->service->get($this->helper->getUID(), $id); - return $this->helper->getNoteData($note, $exclude); + $noteData = $this->helper->getNoteData($note, $exclude); + return (new JSONResponse($noteData)) + ->setETag($noteData['etag']) + ; }); } diff --git a/package-lock.json b/package-lock.json index a8c1a85dd..3c0c57bd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5029,6 +5029,19 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -14816,6 +14829,12 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "optional": true + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",