I am trying to make a form work. This is my code: I copied it from here:https://functions.netlify.com/playground/#hello%2C-%7Bname%7D-(post-version)
const handler = async (event, context) => {
// Only allow POST
if (event.httpMethod !== "POST") {
return { statusCode: 405, body: "Method Not Allowed" };
}
// When the method is POST, the name will no longer be in the event’s
// queryStringParameters – it’ll be in the event body encoded as a query string
const params = querystring.parse(event.body);
console.log(params);
const { firstname, lastname, country } = params;
// maak er een object van dat de data terugstuurt naar de user
const userData = {
firstname,
lastname,
country
}
return {
statusCode: 200,
body: JSON.stringify(userData),
};
};
module.exports = {handler};
The code comes up in vscode like this: https://i.stack.imgur.com/lhX7G.png
The querystring seems deprecated but I can’t seem to get it to work with URLSearchParams. Can somebody help me out?