arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Service Broker Delegator

Manipulating HTTP Response

Streaming Request/Response

hashtag
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.

hashtag
1.1. REST file upload example

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.

hashtag
1.2. GraphQL file upload example

When is mapped to above GraphQL API schema. GraphQL protocol plugin will delegate action call with params as below.

For WebSocket protocol, see 4.

hashtag
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.

For GraphQL protocol, above features just ignored.

For WebSocket protocol, see 4.

hashtag
3. Modify Response Header/Status

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

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

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

hashtag
4. Bidirectional Streaming

WebSocket protocol supports bidirectional streaming. // TODO: documentation

Bidirectional Streaming

GraphQL multipart/form-data requestarrow-up-right
{
  method: "POST",
  action: "file.upload",
  params: "@body.file",
}
{
  filename: string;
  encoding: "utf8"|"7bit"|"base64"|...;
  mimetype: string;
  createReadStream(): ReadableStream;
}
{
    typeDefs: `
        extend type Mutation {
            uploadFile(file: Upload): JSON
        }
    `,
    resolvers: {
      Mutation:  {
        uploadFile: {
          call: "file.upload", 
          params: "@args.file",
        },
      },
    },
}
{
  filename: string;
  encoding: "utf8"|"7bit"|"base64"|...;
  mimetype: string;
  createReadStream(): ReadableStream;
}
{
  createReadStream(): ReadableStream,
  ...,
}
{
  createReadStream(): ReadableStream,
  $headers: {
    "Content-Type": "text/html; charset=utf-8",
  },
}
{
  $headers: {
    "Status": "301 Moved Permanently",
    "Location": "https://some.where.to.go.com",
  },
  $status: 302,
}