Skip to content

Commit a413661

Browse files
committed
Update code example
1 parent 408a77d commit a413661

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class MySiteTreeEndpoint extends RestApiEndpoint
6969
],
7070
];
7171
}
72-
7372
```
7473

7574
Run `https://mysite.test/dev/build?flush=1`
@@ -356,10 +355,11 @@ For instance the following javascript code will make a `GET` request that includ
356355

357356
```js
358357
fetch(
359-
'/api/teams',
360-
headers: {'X-CSRF-TOKEN': window.ss.config['SecurityID']}
358+
'/api/pages',
359+
{ headers: { 'X-CSRF-TOKEN': window.ss.config.SecurityID } }
361360
)
362-
.then(response => console.log(response.json()))
361+
.then(response => response.json())
362+
.then(responseJson => console.log(responseJson));
363363
```
364364

365365
## Extension hooks<a name="readme-extension-hooks"></a>
@@ -400,6 +400,7 @@ class MySiteTreeEndpoint extends RestApiEndpoint
400400
```
401401

402402
Notes:
403+
403404
- If your extension hook updates the DataObject or another DataObject then it is likely you should use a different extension hook such as `onAfterWrite()` on the Dataobject itself rather than on the endpoint. This is because it usually shouldn't matter whether the object was created/updated/deleted via the API or a different way. These hooks are intended to facilitate the implementation of API specific code such as logging operations done via the API.
404405
- For the `onView*()` hooks if you are adding extra data to the JSON for the response, remember to call `canView()` for any DataObjects being added as required.
405406
- For the `onEdit*Write()` hooks you may find it useful to get the fields changed in the operations with `$obj->getChangedFields()`.

0 commit comments

Comments
 (0)