diff --git a/docs/1.guide/10.tasks.md b/docs/1.guide/10.tasks.md index e50d74304a..26def03421 100644 --- a/docs/1.guide/10.tasks.md +++ b/docs/1.guide/10.tasks.md @@ -133,24 +133,65 @@ This endpoint returns a list of available task names and their meta. "description": "Update CMS content" } }, - "scheduledTasks": { - "* * * * *": [ - "cms:update" - ] - } + "scheduledTasks": [ + { + "cron": "* * * * *", + "tasks": [ + "cms:update" + ] + } + ] } ``` #### `/_nitro/tasks/:name` -This endpoint executes a task. You can provide a payload using both query parameters and body JSON payload. +This endpoint executes a task. You can provide a payload using both query parameters and body JSON payload. The payload sent in the JSON body payload must be under the `"payload"` property. -```json -// [GET] /_nitro/tasks/db:migrate +::code-group +```ts [tasks/echo/payload.ts] +export default defineTask({ + meta: { + name: "echo:payload", + description: "Returns the provided payload", + }, + run({ payload, context }) { + console.log("Running echo task..."); + return payload; + }, +}); +``` +```json [GET] +// [GET] /_nitro/tasks/echo:payload?field=value&array=1&array=2 { - "result": "Database migrations completed!" + "field": "value", + "array": ["1", "2"] } ``` +```json [POST] +/** + * [POST] /_nitro/tasks/echo:payload?field=value + * body: { + * "payload": { + * "answer": 42, + * "nested": { + * "value": true + * } + * } + * } + */ +{ + "field": "value", + "answer": 42, + "nested": { + "value": true + } +} +``` +:: + +> [!NOTE] +> The JSON payload included in the body will overwrite the keys present in the query params. ### Using CLI