Skip to content

Commit

Permalink
docs(tasks): update dev server usage (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
noook committed Mar 15, 2024
1 parent 0f089d3 commit c5dbb45
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions docs/1.guide/10.tasks.md
Expand Up @@ -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

Expand Down

0 comments on commit c5dbb45

Please sign in to comment.