Skip to content

Instantly share code, notes, and snippets.

@kenny-io
Created July 29, 2023 18:53
Show Gist options
  • Select an option

  • Save kenny-io/3f3fbbaa9bc67c164fde8abba0dced4d to your computer and use it in GitHub Desktop.

Select an option

Save kenny-io/3f3fbbaa9bc67c164fde8abba0dced4d to your computer and use it in GitHub Desktop.

Revisions

  1. kenny-io created this gist Jul 29, 2023.
    40 changes: 40 additions & 0 deletions price-odb.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    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)