Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

:alien: API

Liyas Thomasbd1d81c1b89c
diff --git a/functions/api.js b/functions/api.js
new file mode 100644
index 000000000..5e95b8332
--- /dev/null
+++ b/functions/api.js
@@ -0,0 +1,21 @@
+// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method
+exports.handler = async (event, context) => {
+ switch (event.httpMethod) {
+ case "GET":
+ try {
+ const name = event.queryStringParameters.name || "World"
+ 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" }
+ }
+}
diff --git a/netlify.toml b/netlify.toml
new file mode 100644
index 000000000..ea43d468c
--- /dev/null
+++ b/netlify.toml
@@ -0,0 +1,3 @@
+[build]
+ command = "npm run generate"
+ functions = "functions/"