How to specify HTTP method on netlify functions

I want to create an API endpoint that would respond to a GET request. It seems functions default to POST. Is this editable?

Hi @mkrecny, thanks for posting and welcome.

The event argument passed to the handler function is an object which contains the attribute httpMethod. You can use an if statement to check the type of request and respond accordingly.

Kindly check the code below to respond to only GET request.

exports.handler = async (event, context) => {
  // Respond to only GET
  if (event.httpMethod === "GET") {
    return { statusCode: 200, body: "Your body content" };

Let me know if the code above works for your scenario.