MCPcopy Create free account
hub / github.com/awsrun/aws-microservices / apiGatewayInvocation

Function apiGatewayInvocation

src/ordering/index.js:67–105  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

65}
66
67const apiGatewayInvocation = async (event) => {
68 // GET /order
69 // GET /order/{userName}
70 let body;
71
72 try {
73 switch (event.httpMethod) {
74 case "GET":
75 if (event.pathParameters != null) {
76 body = await getOrder(event);
77 } else {
78 body = await getAllOrders();
79 }
80 break;
81 default:
82 throw new Error(`Unsupported route: "${event.httpMethod}"`);
83 }
84
85 console.log(body);
86 return {
87 statusCode: 200,
88 body: JSON.stringify({
89 message: `Successfully finished operation: "${event.httpMethod}"`,
90 body: body
91 })
92 };
93 }
94 catch(e) {
95 console.error(e);
96 return {
97 statusCode: 500,
98 body: JSON.stringify({
99 message: "Failed to perform operation.",
100 errorMsg: e.message,
101 errorStack: e.stack,
102 })
103 };
104 }
105}
106
107const getOrder = async (event) => {
108 console.log("getOrder");

Callers 1

index.jsFile · 0.85

Calls 2

getOrderFunction · 0.85
getAllOrdersFunction · 0.85

Tested by

no test coverage detected