Skip to main content
In this tutorial, we’ll use the @spree/sdk TypeScript SDK to consume the Brand API endpoints we created in the API tutorial, and work with the extended Product data that now includes brand information.
This guide assumes you’ve completed the API tutorial and have the Brand endpoints running.

What We’re Building

By the end of this tutorial, you’ll have:
  • Typed calls to your custom Brand endpoints using client.request
  • Extended Product types that include brand data
  • A working brand page example that ties it all together

How the SDK Works

The @spree/sdk package provides a typed client for the Store API:
Under the hood, createClient() creates a request function that handles auth headers (x-spree-api-key), retries with exponential backoff, and URL building. All requests go through the base path /api/v3/store, so client.products.list() calls GET /api/v3/store/products.

Calling Custom Endpoints

The client exposes a request method — the same function that powers all built-in resources. Use it to call any Store API endpoint, including custom ones:
client.request has the same auth headers, retry logic, and locale/currency defaults as all built-in resources. The type parameter (<Brand>, <PaginatedResponse<Brand>>) gives you full type safety on the response.

Step 1: Define Brand Types

Create a types file for your custom Brand resource:
types/brand.ts

Step 2: Work with Extended Product Responses

The Product serializer now includes brand_id and an expandable brand association.

Fetching Products with Brand Data

Filtering Products by Brand

Ransack predicates work on whitelisted attributes and associations. The API tutorial shows how to register brand_id and brand via Spree.ransack — once that’s done, you can filter:
Ransack predicates like _eq, _cont, _gt, _lt work on whitelisted attributes and associations. See Search & Filtering for the full list.

Complete Example: Brand Page

A real-world example combining everything — fetch a brand by slug and list its products: