Skip to content

Commit 7a1b1f7

Browse files
weltekialexellis
authored andcommitted
Add section on supported content types and streaming options
Add a section to the workload page to list the supported HTTP streaming options: SSE, Websockets and NDJSON. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent ab67c3b commit 7a1b1f7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/reference/workloads.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,37 @@ fprocess=env
240240
HOME=/home/app
241241
Http_X_Forwarded_Proto=https
242242
```
243+
244+
### Supported content types
245+
246+
OpenFaaS supports workloads over HTTP, and most standard content types are supported.
247+
248+
Since OpenFaaS has no hard limit on function execution duration, it allows for maintaining long-lived connections for streaming over HTTP.
249+
250+
> **Important**: Always ensure OpenFaaS system and function timeouts are configured appropriately for your streaming workloads. See [Extended timeouts](https://docs.openfaas.com/tutorials/expanded-timeouts/) for details.
251+
252+
Supported streaming options:
253+
254+
**Server-Sent Events (SSE)**
255+
256+
Server-Sent Events enable a function to push one-way event streams to a client.
257+
258+
- Clients should include an `Accept: text/event-stream` header in their request when starting tht SSE request.
259+
- The function's response `Content-Type` header must be set to `text/event-stream`. Each event data chunk should be prefixed with data: and terminated by two newline characters (\n\n).
260+
261+
For more details on SSE, refer to [Using Server Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
262+
263+
**WebSockets**
264+
265+
WebSockets provide bidirectional, full-duplex communication between a client and an OpenFaaS function.
266+
267+
To create a WebSocket-enabled function, you can modify an existing OpenFaaS template or use the `Dockerfile` template as a starting point.
268+
269+
For a comprehensive guide, check out: [How to Integrate WebSockets with Serverless Functions and OpenFaaS](https://www.openfaas.com/blog/serverless-websockets/)
270+
271+
**Newline Delimited JSON (NDJSON)**
272+
273+
NDJSON (or JSON Lines) is a format for streaming multiple independent JSON objects, each on a new line.
274+
275+
- Clients should include an `Accept: application/x-ndjson` header in their request.
276+
- The function's response `Content-Type` header should be set to `application/x-ndjson`. Each line in the response should be a complete JSON object followed by a newline character (\n).

0 commit comments

Comments
 (0)