> For the complete documentation index, see [llms.txt](https://moleculer-api.gitbook.io/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://moleculer-api.gitbook.io/api/development/service-broker-delegator/streaming.md).

# Streaming Request/Response

## 1. Streaming Request

Handling streaming request is up to delegator. To support streaming request, delegator should handle `{ createReadStream(): ReadableStream, ...meta: any }` params as their own way.

### 1.1. REST file upload example

```javascript
{
  method: "POST",
  action: "file.upload",
  params: "@body.file",
}
```

When multipart/form-data request with 'file' field is mapped to above REST API schema. REST protocol plugin will delegate action call with params as below.

```
{
  filename: string;
  encoding: "utf8"|"7bit"|"base64"|...;
  mimetype: string;
  createReadStream(): ReadableStream;
}
```

### 1.2. GraphQL file upload example

```javascript
{
    typeDefs: `
        extend type Mutation {
            uploadFile(file: Upload): JSON
        }
    `,
    resolvers: {
      Mutation:  {
        uploadFile: {
          call: "file.upload", 
          params: "@args.file",
        },
      },
    },
}
```

When [GraphQL multipart/form-data request](https://github.com/jaydenseric/graphql-multipart-request-spec#graphql-multipart-request-specification) is mapped to above GraphQL API schema. GraphQL protocol plugin will delegate action call with params as below.

```
{
  filename: string;
  encoding: "utf8"|"7bit"|"base64"|...;
  mimetype: string;
  createReadStream(): ReadableStream;
}
```

For WebSocket protocol, see 4.

## 2. Streaming Response

Handling streaming response is up to protocol plugins. For REST protocol, any response from delegator like below will be handled as stream response with `{ "Content-Type": "application/octet-stream", "Transfer-Encoding": "chunked" }` headers.

```
{
  createReadStream(): ReadableStream,
  ...,
}
```

For GraphQL protocol, above features just ignored.

For WebSocket protocol, see 4.

## 3. Modify Response Header/Status

Also for REST protocol, can modify response with `$headers`, `status` properties in delegator response.

```
{
  createReadStream(): ReadableStream,
  $headers: {
    "Content-Type": "text/html; charset=utf-8",
  },
}
```

It is not only for the streaming response. below delegator response will also modify response headers.

```
{
  $headers: {
    "Status": "301 Moved Permanently",
    "Location": "https://some.where.to.go.com",
  },
  $status: 302,
}
```

For GraphQL protocol, this feature is just ignored. For WebSocket protocol, this feature is just ignored.

## 4. Bidirectional Streaming

WebSocket protocol supports bidirectional streaming. // TODO: documentation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://moleculer-api.gitbook.io/api/development/service-broker-delegator/streaming.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
