I am perfectly aware that it may be my limited knowledge on the JS eco system, but I have not found a warking way to access POSTed data in a deno http Server.
What do I have to do here?
// example Server async function handler(req: Request): Promise<Response> { const url = new URL(req.url); const path = url.pathname; const method = req.method; let module;
console.log( req)
if ("GET" === method) { return new Response("Hello", { status: 200 }) }
if ("POST" === method) { // What do I have to do here, to get the data? // I've tried: readAll // const buf = await req.body(); // const buf = await readAll(req.body); // const json = JSON.parse(decoder.decode(buf)); // const decoder = new TextDecoder(); // decoder.decode( req.body) // const body = await req.formData() return new Response("Hello, where's my data?", { status: 200 }) }
return new Response("Method not implemented", { status: 501 }); }
Deno.serve(handler);
// Following is an example curl call: curl -d "param1=value1¶m2=value2" -X POST http://localhost:8000/test