Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created December 19, 2021 13:10
Show Gist options
  • Select an option

  • Save leegilmorecode/1f73f423627b3caa604774d873b6da6d to your computer and use it in GitHub Desktop.

Select an option

Save leegilmorecode/1f73f423627b3caa604774d873b6da6d to your computer and use it in GitHub Desktop.
import axios from "axios";
type Stock = {
stockId: number;
description: string;
};
type StockResponse = {
stock: Stock[];
};
async function handler(): Promise<{ body: string; statusCode: number }> {
console.log("create-order.handler - started");
const domain = process.env.STOCK_DOMAIN;
console.log(`create-order.handler - calling: https://${domain}/prod/stock`); // e.g. stock.yourdomain.co.uk
const result = await axios.get(
`https://${domain}/prod/stock`, // this is the private api dns entry
{
headers: {
"x-api-key": "super-secret-api-key", // this is the api key for our private api
},
}
);
const data: StockResponse = result.data;
console.log(`create-order.handler - private call is successful: ${data}`);
return {
body: JSON.stringify(data),
statusCode: 200,
};
}
module.exports = { handler };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment