How To Pass JSON to httpfunctions.js

Hi there,

This is how the request should be sent.

const requestPayload = {..} // An object of data

return fetch('https://api.provider.net/..', {
    method: 'POST',
    headers: { 'accept': 'application/json', 'content-type': 'application/json' },
    body: JSON.stringify(requestPayload);
})

This is how you should handle the received JSON.

// backend/http-functions.js

export async function use_function(request) {
    if (requst.method === 'POST' || requst.method === 'PUT') {
        const payload = await request.body.json().catch(e => { return null })
    }
}

Hope this helps~!
Ahmad