Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 3/serverless api #519

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# terraform
**/.terraform/*
terraform.tfstate
terraform.tfstate.backup
22 changes: 22 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions fa-products-service/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
getting_started.md
node_modules/@types/
node_modules/azure-functions-core-tools/
node_modules/typescript/
48 changes: 48 additions & 0 deletions fa-products-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
bin
obj
csx
.vs
edge
Publish

*.user
*.suo
*.cscfg
*.Cache
project.lock.json

/packages
/TestResults

/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json
local.settings.json

node_modules
dist

# Local python packages
.python_packages/

# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
5 changes: 5 additions & 0 deletions fa-products-service/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
15 changes: 15 additions & 0 deletions fa-products-service/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
20 changes: 20 additions & 0 deletions fa-products-service/http-get-product-by-id/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"route": "products/{productId}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/http-get-product-by-id/index.js"
}
7 changes: 7 additions & 0 deletions fa-products-service/http-get-product-by-id/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
22 changes: 22 additions & 0 deletions fa-products-service/http-get-product-by-id/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { products } from "../shared-data";

const getProductById: AzureFunction = async function(context: Context, req: HttpRequest): Promise<void> {
const productId = context.bindingData.productId.toString();

const product = products.find(p => p.id === productId);

if (product) {
context.res = {
body: product
};
} else {
context.res = {
status: 404,
body: `Product with ID: ${productId} not found`
};
}
};

export default getProductById;

20 changes: 20 additions & 0 deletions fa-products-service/http-get-products/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"route": "products"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/http-get-products/index.js"
}
13 changes: 13 additions & 0 deletions fa-products-service/http-get-products/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import { products } from "../shared-data";

const getProducts: AzureFunction = async function(
context: Context,
req: HttpRequest
): Promise<void> {
context.res = {
body: products,
};
};

export default getProducts;
Loading