sholladay / pogo

Server framework for Deno
Mozilla Public License 2.0
482 stars 32 forks source link

Make request.body a getter #21

Closed ZPiDER666 closed 4 years ago

ZPiDER666 commented 4 years ago

in the raw request the body function is a getter, so we need to wrap it as a getter here too, otherwise we will not be able to read from the result.

now the following code will work properly. i think in the future it will be convenient to have a function just returning the body as string.

async function getBody(request:pogo.Request) {
    console.log("MAIN.GETBODY");
    const br = request.body;
    const bufferContent = await Deno.readAll(br);
    const bodyText = new TextDecoder().decode(bufferContent);
    return JSON.parse(bodyText);
}