From d5896db21201fbc50e1699177eebbaf516548f5f Mon Sep 17 00:00:00 2001 From: Scott McKenzie Date: Wed, 30 Nov 2022 07:22:26 +1100 Subject: [PATCH 1/4] Setup api folder --- {api-starter => api}/.funcignore | 0 {api-starter => api}/.gitignore | 0 {api-starter => api}/README.md | 0 {api-starter => api}/host.json | 0 {api-starter => api}/package-lock.json | 0 {api-starter => api}/package.json | 0 {api-starter => api}/products-delete/function.json | 0 {api-starter => api}/products-delete/index.js | 0 {api-starter => api}/products-post/function.json | 0 {api-starter => api}/products-post/index.js | 0 {api-starter => api}/products-put/function.json | 0 {api-starter => api}/products-put/index.js | 0 {api-starter => api}/proxies.json | 0 {api-starter => api}/shared/product-data.js | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename {api-starter => api}/.funcignore (100%) rename {api-starter => api}/.gitignore (100%) rename {api-starter => api}/README.md (100%) rename {api-starter => api}/host.json (100%) rename {api-starter => api}/package-lock.json (100%) rename {api-starter => api}/package.json (100%) rename {api-starter => api}/products-delete/function.json (100%) rename {api-starter => api}/products-delete/index.js (100%) rename {api-starter => api}/products-post/function.json (100%) rename {api-starter => api}/products-post/index.js (100%) rename {api-starter => api}/products-put/function.json (100%) rename {api-starter => api}/products-put/index.js (100%) rename {api-starter => api}/proxies.json (100%) rename {api-starter => api}/shared/product-data.js (100%) diff --git a/api-starter/.funcignore b/api/.funcignore similarity index 100% rename from api-starter/.funcignore rename to api/.funcignore diff --git a/api-starter/.gitignore b/api/.gitignore similarity index 100% rename from api-starter/.gitignore rename to api/.gitignore diff --git a/api-starter/README.md b/api/README.md similarity index 100% rename from api-starter/README.md rename to api/README.md diff --git a/api-starter/host.json b/api/host.json similarity index 100% rename from api-starter/host.json rename to api/host.json diff --git a/api-starter/package-lock.json b/api/package-lock.json similarity index 100% rename from api-starter/package-lock.json rename to api/package-lock.json diff --git a/api-starter/package.json b/api/package.json similarity index 100% rename from api-starter/package.json rename to api/package.json diff --git a/api-starter/products-delete/function.json b/api/products-delete/function.json similarity index 100% rename from api-starter/products-delete/function.json rename to api/products-delete/function.json diff --git a/api-starter/products-delete/index.js b/api/products-delete/index.js similarity index 100% rename from api-starter/products-delete/index.js rename to api/products-delete/index.js diff --git a/api-starter/products-post/function.json b/api/products-post/function.json similarity index 100% rename from api-starter/products-post/function.json rename to api/products-post/function.json diff --git a/api-starter/products-post/index.js b/api/products-post/index.js similarity index 100% rename from api-starter/products-post/index.js rename to api/products-post/index.js diff --git a/api-starter/products-put/function.json b/api/products-put/function.json similarity index 100% rename from api-starter/products-put/function.json rename to api/products-put/function.json diff --git a/api-starter/products-put/index.js b/api/products-put/index.js similarity index 100% rename from api-starter/products-put/index.js rename to api/products-put/index.js diff --git a/api-starter/proxies.json b/api/proxies.json similarity index 100% rename from api-starter/proxies.json rename to api/proxies.json diff --git a/api-starter/shared/product-data.js b/api/shared/product-data.js similarity index 100% rename from api-starter/shared/product-data.js rename to api/shared/product-data.js From f692274ff1cfe0f45322cd8b5229c2dac1d3ab28 Mon Sep 17 00:00:00 2001 From: Scott McKenzie Date: Wed, 30 Nov 2022 08:17:54 +1100 Subject: [PATCH 2/4] Update ExtensionBundle version --- api/host.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/host.json b/api/host.json index d342a8e..c4ae96f 100644 --- a/api/host.json +++ b/api/host.json @@ -2,6 +2,6 @@ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[1.*, 2.0.0)" + "version": "[2.*, 3.0.0)" } } From be73b16a2bf8afee2ca0c1cfd352e3023b25ce35 Mon Sep 17 00:00:00 2001 From: Scott McKenzie Date: Wed, 30 Nov 2022 08:18:09 +1100 Subject: [PATCH 3/4] Add products-get function --- api/products-get/function.json | 19 +++++++++++++++++++ api/products-get/index.js | 13 +++++++++++++ api/products-get/sample.dat | 3 +++ 3 files changed, 35 insertions(+) create mode 100644 api/products-get/function.json create mode 100644 api/products-get/index.js create mode 100644 api/products-get/sample.dat diff --git a/api/products-get/function.json b/api/products-get/function.json new file mode 100644 index 0000000..72a6566 --- /dev/null +++ b/api/products-get/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get" + ], + "route": "products" + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} \ No newline at end of file diff --git a/api/products-get/index.js b/api/products-get/index.js new file mode 100644 index 0000000..e785f8b --- /dev/null +++ b/api/products-get/index.js @@ -0,0 +1,13 @@ +module.exports = async function (context, req) { + const data = require('../shared/product-data'); + + module.exports = async function (context, req) { + try { + const products = data.getProducts(); + context.res.status(200).json(products); + } + catch (error) { + context.res.status(500).send(error); + } + } +} diff --git a/api/products-get/sample.dat b/api/products-get/sample.dat new file mode 100644 index 0000000..2e60943 --- /dev/null +++ b/api/products-get/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file From 25411be0399287e9ef7e5b2bc1e529a0266df3f2 Mon Sep 17 00:00:00 2001 From: Scott McKenzie Date: Wed, 30 Nov 2022 08:32:03 +1100 Subject: [PATCH 4/4] Fix products-get --- api/products-get/index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/api/products-get/index.js b/api/products-get/index.js index e785f8b..21cc04e 100644 --- a/api/products-get/index.js +++ b/api/products-get/index.js @@ -1,13 +1,11 @@ -module.exports = async function (context, req) { - const data = require('../shared/product-data'); +const data = require('../shared/product-data'); - module.exports = async function (context, req) { - try { - const products = data.getProducts(); - context.res.status(200).json(products); - } - catch (error) { - context.res.status(500).send(error); - } +module.exports = async function (context, req) { + try { + const products = data.getProducts(); + context.res.status(200).json(products); + } + catch (error) { + context.res.status(500).send(error); } }