api-client/functions/api.js

22 lines
645 B
JavaScript
Raw Normal View History

2020-03-12 14:45:49 +00:00
// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method
2020-06-11 14:25:40 +00:00
export async function handler({ httpMethod, queryStringParameters }, context) {
switch (httpMethod) {
2020-03-12 14:45:49 +00:00
case "GET":
try {
2020-06-11 14:25:40 +00:00
const name = queryStringParameters.name || "World"
2020-03-12 14:45:49 +00:00
return {
statusCode: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ message: `Hello ${name}` }),
}
} catch (err) {
return { statusCode: 500, body: err.toString() }
}
default:
return { statusCode: 405, body: "Method Not Allowed" }
}
}