Skip to content

JavaScript APIs

This guide provides an overview of JavaScript APIs essential for building core storefront functionalities. These APIs serve as reliable tools to ensure stability and efficiency in your custom implementations.

Why you should use JavaScript APIs?

JavaScript APIs act as stable contracts between our platform and your code. Regardless of internal implementation, these APIs are designed to ensure backward compatibility, allowing your code to function seamlessly and return the expected results without needing adjustments.

Returning an API

You can access each API either synchronously or asynchronously:

  • Synchronous Access: Returns the API object immediately.
  • Asynchronous Access: Returns a Promise that resolves to the specified API.
useStorefront((storefront) => {
    const httpRequesterApi = storefront.getApiSync('HTTPRequesterApi'); // synchronous
    const httpRequesterApiAsync = storefront.getApi('HTTPRequesterApi'); // asynchronous
});

Remember to use either an async/await or a then when accessing an API asynchronously to ensure a seamless implementation

useStorefront(async (storefront) => {
    const httpRequesterApi = await storefront.getApi('HTTPRequesterApi');
});
useStorefront((storefront) => {
    storefront.getApi('HTTPRequesterApi').then((api) => {
        // do something with API
    });
});

Objects

Some custom objects are frequently used across multiple APIs. We have gathered all general-purpose objects in this directory to streamline your reference experience.

Available APIs