66 * An example on how to enable streaming for API Gateway REST API routes.
77 *
88 * ```ts title="sst.config.ts"
9- * api.route("GET /", "index.handler", {
9+ * api.route("GET /", {
10+ * handler: "index.handler",
1011 * streaming: true,
1112 * });
1213 * ```
1617 *
1718 * ```ts title="index.ts"
1819 * export const handler = awslambda.streamifyResponse(
19- * async (_event: unknown, responseStream: any ) => {
20- * responseStream = awslambda.HttpResponseStream.from(responseStream , {
20+ * async (event, stream ) => {
21+ * stream = awslambda.HttpResponseStream.from(stream , {
2122 * statusCode: 200,
22- * headers: { "Content-Type": "text/plain" },
23+ * headers: {
24+ * "Content-Type": "text/plain; charset=UTF-8",
25+ * "X-Content-Type-Options": "nosniff",
26+ * },
2327 * });
2428 *
25- * responseStream .write("Hello");
29+ * stream .write("Hello ");
2630 * await new Promise((resolve) => setTimeout(resolve, 3000));
27- * responseStream.write(" World");
28- * responseStream.end();
31+ * stream.write("World");
32+ *
33+ * stream.end();
2934 * },
3035 * );
3136 * ```
3237 *
33- * :::note
34- * Streaming is currently not supported in `sst dev`.
35- * :::
36- *
37- * To test this in your terminal, use the `curl` command with the `--no-buffer` option.
38- *
39- * ```bash "--no-buffer"
40- * curl --no-buffer https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod
41- * ```
42- *
4338 */
4439export default $config ( {
4540 app ( input ) {
@@ -51,10 +46,12 @@ export default $config({
5146 } ,
5247 async run ( ) {
5348 const api = new sst . aws . ApiGatewayV1 ( "MyApi" ) ;
54- api . route ( "GET /" , "index.handler" , {
49+ api . route ( "GET /" , {
50+ handler : "index.handler" ,
5551 streaming : true ,
5652 } ) ;
57- api . route ( "GET /hono" , "hono.handler" , {
53+ api . route ( "GET /hono" , {
54+ handler : "hono.handler" ,
5855 streaming : true ,
5956 } ) ;
6057 api . deploy ( ) ;
0 commit comments