Skip to main content

JSON Api

To create a JSON connector, it is recommended to use a hyperscaler such as Google Cloud or Amazon Web Services (AWS). Please consider the following code snippet of a Google Cloud Function that retrieves a feed of products to be used in the Product Feed module. For persistence, it is recommended to use a managed database, such as Google Datastore.

const functions = require('@google-cloud/functions-framework')

functions.http('productFeed', (req, res) => {
const products = [
{
title: 'Product 1',
description: 'Product 1 description',
price: '€10.99',
url: 'https://example.com/product-1',
tags: ['tag1', 'tag2']
},
{
title: 'Product 2',
description: 'Product 2 description',
price: '€20.99',
url: 'https://example.com/product-2',
tags: ['tag1', 'tag3']
}
]

res.setHeader('Content-type', 'application/json')
res.send(JSON.stringify(products))
})