Hello, i want to question, can I use post request inside the netlify function ?
because i’ve been debugging, and i still can’t using post request,
const axios = require('axios')
const FormData = require('form-data')
module.exports.handler = async function(event, context) {
try {
const item = {
"origin": '501',
"originType": 'city',
"destination": '496',
"destinationType": 'subdistrict',
"weight": 1700,
"courier": 'jne'
}
var formData = new FormData()
for(let key in item) {
formData.append(key, item[key]);
}
const res = await axios.post(`https://pro.rajaongkir.com/api/cost`, {
headers: {
key: process.env.KEY,
'Access-Control-Allow-Origin': '*',
},
// body: JSON.stringify(item)
body: formData
})
return {
statusCode: res.status,
body: JSON.stringify(res.data)
}
} catch(e) {
return {
statusCode: 400,
body: JSON.stringify(e)
}
}
}
I’ve tried to send as formData or as plain object, and nothing works.
do i have to purchase plan or something first like firebase ? (firebase requires me to purchase blaze for posting request to external server) but imnot sure i dont read any here.
also i want to confirm, it seems netlify function cannot process FormData ? i’ve read it somewhere but i dont know.