How to call rest api ("/api/products")with authentication in storefront of shopify?

I need to call the rest api from theme app extension that is “/api/configdatashow” in node js template of shopify

they had provided but my problem is that I am not able to use this in my theme app extension using fetch call , i had also provided shopify domain that is shop url and access token but I am not able to get the data which is store in my database . Error occurs about “No shop provided” .But without usage of this app.use(“/api/*”, shopify.validateAuthenticatedSession()); I wont be able to get authenticate in my theme app extension .

What is the proper way to call the api from theme app extension ?

To call a REST API from a Shopify theme app extension using Node.js, you can utilize the fetch function with the appropriate headers and parameters. Here’s an example of how you can make the API call:

const fetch = require('node-fetch');
const shopUrl = 'your-shop-url.myshopify.com';
const accessToken = 'your-access-token';

const apiUrl = `https://${shopUrl}/api/configdatashow`;

fetch(apiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': accessToken,
},
})
.then((response) => response.json())
.then((data) => {
console.log('API response:', data);
// Process the data returned from the API
})
.catch((error) => {
console.error('API error:', error);
});

Make sure to replace ‘your-shop-url.myshopify.com’ with your actual Shopify shop URL and ‘your-access-token’ with your valid access token. Also, ensure that the API endpoint ‘/api/configdatashow’ is correct and matches the endpoint provided by your app.

By including the ‘X-Shopify-Access-Token’ header in the request, you authenticate the API call with the access token, which should grant you access to the protected resources.

Note that this example assumes you have the necessary dependencies installed and are using a Node.js environment. Adjustments may be required based on your specific implementation and requirements.