aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-13 02:27:54 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-13 02:27:54 -0700
commitb0a7f8df926e91d3b2f0b3b8833ddaf55073f30e (patch)
treeb363b5670b6a631e4adc383a71a064f1f51ee164 /examples
parent32e16bda23976cfb4efc06ce779fcf99604b1b3f (diff)
downloadbun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.tar.gz
bun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.tar.zst
bun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.zip
Create http-request-body.ts
Diffstat (limited to 'examples')
-rw-r--r--examples/http-request-body.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/http-request-body.ts b/examples/http-request-body.ts
new file mode 100644
index 000000000..6ce356ce0
--- /dev/null
+++ b/examples/http-request-body.ts
@@ -0,0 +1,16 @@
+import { serve } from "bun";
+
+serve({
+ async fetch(req) {
+ // body is a ReadableStream
+ const body = req.body;
+
+ const writer = Bun.file(`upload.${Date.now()}.txt`).writer();
+ for await (const chunk of body) {
+ writer.write(chunk);
+ }
+ const wrote = await writer.end();
+
+ return Response.json({ wrote, type: req.headers.get("Content-Type") });
+ },
+});