api-client/netlify/api.js

22 lines
623 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-12 03:25:17 +00:00
exports.handler = async (event, context) => {
switch (event.httpMethod) {
2020-03-12 14:45:49 +00:00
case "GET":
try {
2020-06-12 03:25:17 +00:00
const name = event.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" }
}
}