Skip to content

Instantly share code, notes, and snippets.

@kenny-io
Created July 29, 2023 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenny-io/3f3fbbaa9bc67c164fde8abba0dced4d to your computer and use it in GitHub Desktop.
Save kenny-io/3f3fbbaa9bc67c164fde8abba0dced4d to your computer and use it in GitHub Desktop.
import { builder } from '@netlify/functions';
import { fetch } from 'node-fetch';
async function handler(event, context) {
// Get the product ID from URL path
const segments = event.path.split('/');
const productId = segments[segments.length - 1];
// Fetch the product price from the API
const response = await fetch(`https://api.example.com/products/${productId}`);
const price = await response.json();
// Generate the pricing table
const table = `
<table>
<thead>
<tr>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>${price.price}</td>
</tr>
<tr>
<td>2</td>
<td>${price.price * 2}</td>
</tr>
<tr>
<td>3</td>
<td>${price.price * 3}</td>
</tr>
</tbody>
</table> ;`
// Return the pricing table
return {
statusCode: 200,
body: table,
};
}
export default builder(handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment