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 Mar 13, 2021
1 parent c2ca8a8 commit 0e1c4f4
Show file tree
Hide file tree
Showing 2 changed files with 6 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 @@ -81,9 +81,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 @@ -63,7 +63,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

0 comments on commit 0e1c4f4

Please sign in to comment.