mirror of
https://github.com/directus/directus.git
synced 2026-01-22 20:47:54 -05:00
Add "require('axios')" in API hooks examples (#6360)
* Docs: Add "require('axios')" in API hooks examples
* Move "require('axios')" to top
This commit is contained in:
@@ -111,6 +111,8 @@ provide a cron statement in the event scope as follows: `cron(<statement>)`, for
|
||||
on day-of-month 1) or `cron(5 4 * * sun)` (at 04:05 on Sunday). See example below:
|
||||
|
||||
```js
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = function registerHook() {
|
||||
return {
|
||||
'cron(*/15 * * * *)': async function () {
|
||||
@@ -125,6 +127,8 @@ module.exports = function registerHook() {
|
||||
Each custom hook is registered to its event scope using a function with the following format:
|
||||
|
||||
```js
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = function registerHook() {
|
||||
return {
|
||||
'items.create': function () {
|
||||
@@ -188,10 +192,12 @@ To deploy your hook, simply restart the API by running:
|
||||
npx directus start
|
||||
```
|
||||
|
||||
## Full Example:
|
||||
## Full Example
|
||||
|
||||
`extensions/hooks/sync-with-external/index.js`:
|
||||
|
||||
```js
|
||||
// extensions/hooks/sync-with-external/index.js
|
||||
const axios = require('axios');
|
||||
|
||||
module.exports = function registerHook({ services, exceptions }) {
|
||||
const { MailService } = services;
|
||||
|
||||
Reference in New Issue
Block a user