BlankeosB
Convex Community3y ago
5 replies
Blankeos

await request.json() destructuring body?

// handler
export const registerHTTP = httpAction(async (ctx, request) => {
    const { body } = await request.json();

    console.log(`Sent via HTTP action: ${body}`);

    return new Response(null, {
        headers: new Headers({
            'Content-Type': 'application/json'
        })
});

fetch(url + '/test-api', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        email: 'test@gmail.com',
        username: 'test',
    })
}).then(async (res) => {
    if (res.ok) {
        const json = await res.json();
        console.log(json);
    }
    {
        console.log(res.statusText);
    }
});


I'm getting 200, but all I'm getting on the logs is:
log
'Sent via HTTP action: undefined'
Was this page helpful?