Skip to content

Commit 068969a

Browse files
authored
docs: Custom content type for synchronous endpoints (windmill-labs#424)
1 parent 28306f8 commit 068969a

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

docs/core_concepts/4_webhooks/index.mdx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Webhooks are a way to interact with Windmill using standard web technologies.
99
Snippet of a Deno/TypeScript script using only native JavaScript to trigger a
1010
webhook can be found on [Windmill Hub][script].
1111

12-
<br/>
12+
<br />
1313

1414
Some use cases include triggering scripts and flows from [Slack](/blog/handler-slack-commands) or [Emails](../../integrations/mailchimp_mandrill.md).
1515

@@ -80,7 +80,6 @@ When using the **synchronous mode**, the webhook returns the result of the scrip
8080

8181
When using the **asynchronous mode**, the webhook returns a `uuid` and you can poll the [get job](https://app.windmill.dev/openapi.html#/operations/getJob) API call to fetch the status and results once it is completed.
8282

83-
8483
## User token
8584

8685
To interact with Windmill you always need to use `Bearer` token authentication.
@@ -189,9 +188,47 @@ Similarly to request headers, if the query args contain `raw=true`, then an addi
189188

190189
## Custom Response Code
191190

192-
For all sync run jobs endpoints, if the response contains a key `windmill_status_code` with a number value, that value will be used as the status code.
191+
For all sync run jobs endpoints, if the response contains a key `windmill_status_code` with a number value, that value will be used as the status code. For example, if a script or flow returns:
192+
193+
```json
194+
{
195+
"windmill_status_code": 201,
196+
"result": {
197+
"Hello": "World"
198+
}
199+
}
200+
```
201+
202+
the synchronous endpoint will return:
203+
204+
```json
205+
{
206+
"Hello": "World"
207+
}
208+
```
209+
210+
with a status code `201`.
211+
212+
Note that if the status code is invalid (w.r.t [RFC9110](https://httpwg.org/specs/rfc9110.html#overview.of.status.codes)), the endpoint will return an error.
213+
214+
## Custom Content Type
215+
216+
Similarly to the above, for all sync run jobs endpoints, if the response contains a key `windmill_content_type`, the associated value will be used as the content type header of the response. For example, if a script or flow returns:
217+
218+
```json
219+
{
220+
"windmill_content_type": "text/csv",
221+
"result": "Hello;World"
222+
}
223+
```
224+
225+
the synchronous endpoint will return:
226+
227+
```csv
228+
"Hello;World"
229+
```
193230

194-
e.g: `{"windmill_status_code": 201}`
231+
with the response header: "Content-Type: text/csv".
195232

196233
## Return early for flows
197234

0 commit comments

Comments
 (0)