Skip to content

Commit

Permalink
API: ETag/If-None-Match for Get single note
Browse files Browse the repository at this point in the history
  • Loading branch information
korelstar committed Apr 19, 2021
1 parent 002dc3f commit a2e054c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/api/v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
;
});
}

Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2e054c

Please sign in to comment.