Storefront SDK

Install the NPM package:

npm install --save @spree/storefront-api-v2-sdk

Install the Node Fetch HTTP client and the Node Fetch fetcher to be able to use it:

npm install --save @spree/node-fetcher node-fetch

If you want to use the Spree SDK for a browser implementation you can use the native fetch without the need to install anything (see here).

Create a client and use it to call Spree:

const createFetchFetcher = require('@spree/node-fetcher/dist/server/index').default
const { makeClient } = require('@spree/storefront-api-v2-sdk')
const client = makeClient({
host: 'http://localhost:3000',
createFetcher: createFetchFetcher
})

client.products.list({
include: 'default_variant',
page: 1
})
.then((spreeResponse) => {
console.log(spreeResponse.success())
})

Spree Storefront SDK can also be imported using import and <script> tags in the browser. Check the Alternative setups section for examples.

For details about HTTP clients, read the Switching the fetcher section.

Platform SDK

Install the NPM package:

npm install --save @spree/platform-api-v2-sdk

Install the Node Fetch HTTP client and the Node Fetch fetcher to be able to use it:

npm install --save @spree/node-fetcher node-fetch

If you want to use the Spree SDK for a browser implementation you can use the native fetch without the need to install anything (see here).

Create a client and use it to call Spree:

const createFetchFetcher = require('@spree/node-fetcher/dist/server/index').default
const { makeClient } = require('@spree/platform-api-v2-sdk')
const client = makeClient({
host: 'http://localhost:3000',
createFetcher: createFetchFetcher
})

client.users.list({
bearer_token: '...'
})
.then((spreeResponse) => {
console.log(spreeResponse.success())
})

Spree Platform SDK can also be imported using import and <script> tags in the browser. Check the Alternative setups section for examples.

For details about HTTP clients, read the Switching the fetcher section.

Generated using TypeDoc