tRPC Client Documentation

@sstraatemans/sw_trpcclient

Type-safe client library for accessing Suske en Wiske (Spike and Suzy) comic data

A fully type-safe tRPC client package that provides auto-generated hooks and utilities for querying Suske en Wiske albums, characters, artists, and collections. Built on top of @trpc/client with full TypeScript support and Zod schema validation.


Table of Contents


Installation

npm

npm install @sstraatemans/sw_trpcclient

yarn

yarn add @sstraatemans/sw_trpcclient

pnpm

pnpm add @sstraatemans/sw_trpcclient

Peer Dependencies

This package requires the following peer dependencies:

npm install superjson zod

Or with pnpm:

pnpm add superjson zod

Quick Start

Get started in just a few lines of code:

import { createClient } from '@sstraatemans/sw_trpcclient';

// 1. Create the client
const trpc = createClient({
  url: 'https://playground-trpcserver.vercel.app/trpc/v1',
});

// 2. Make type-safe queries
const albums = await trpc.albums.all.query({ offset: 0, limit: 10 });
console.log(`Found ${albums.totalCount} albums`);

// 3. Get a specific album by ID
const album = await trpc.albums.getAlbumById.query(1);
console.log(`Album: ${album.title}`);

Client Setup

Basic Usage

The simplest way to set up the client:

import { createClient } from '@sstraatemans/sw_trpcclient';

export const trpcClient = createClient({
  url: 'https://playground-trpcserver.vercel.app/trpc/v1',
});

With Custom Headers

Add authentication or custom headers:

import { createClient } from '@sstraatemans/sw_trpcclient';

export const trpcClient = createClient({
  url: 'https://playground-trpcserver.vercel.app/trpc/v1',
  headers: {
    'x-api-key': process.env.API_KEY,
    'x-client-version': '1.0.0',
  },
});

Or use a function for dynamic headers:

export const trpcClient = createClient({
  url: 'https://playground-trpcserver.vercel.app/trpc/v1',
  headers: async () => {
    const token = await getAuthToken();
    return {
      authorization: `Bearer ${token}`,
    };
  },
});

Configuration Options

interface CreateClientOptions {
  // Server URL (required)
  url: string;

  // Custom transformer (default: superjson)
  transformer?: typeof superjson;

  // HTTP headers for requests
  headers?:
    | Record<string, string>
    | (() => Record<string, string> | Promise<Record<string, string>>);

  // Maximum URL length for batching (default: 4000)
  maxURLLength?: number;

  // Maximum batch items (default: 3)
  maxItems?: number;
}

Example with all options:

import { createClient } from '@sstraatemans/sw_trpcclient';
import superjson from 'superjson';

export const trpcClient = createClient({
  url: 'https://playground-trpcserver.vercel.app/trpc/v1',
  transformer: superjson,
  headers: {
    'x-client-name': 'my-app',
  },
  maxURLLength: 5000,
  maxItems: 5,
});

Documentation


Alternative APIs

Don't want to use tRPC? No problem! The Suske en Wiske data is also available through other APIs:

GraphQL API

Access the data using GraphQL for flexible queries and precise data fetching.

query {
  albums(limit: 10) {
    id
    title
    year
  }
}

GraphQL Endpoint: https://graphql.suskeenwiske.dev/v1

REST API

Use traditional REST endpoints for simple HTTP requests.

curl https://suskeenwiske.dev/api/v1/albums

REST Base URL: https://suskeenwiske.dev/api/v1

For more information about the GraphQL and REST APIs, visit the online documentation.


Features

✨ Fully Type-Safe - Auto-generated TypeScript types from the tRPC server
šŸ”’ Zod Validation - Runtime type checking with Zod schemas
šŸ“¦ Tree-Shakeable - Only import what you need
šŸš€ HTTP Batching - Automatic request batching for better performance
šŸŽÆ IntelliSense - Full autocomplete support in your IDE
🌐 SuperJSON - Native support for Date, Map, Set, BigInt, and more


License

This project is licensed under the ISC License - see the LICENSE file for details.


Disclaimer

The data exposed by this package is not owned by the package author or maintainer. All such data is freely available on the internet from public sources.

The copyright to Suske en Wiske and all related characters, stories, and intellectual property yada yada yada is owned by Standaard Uitgeverij. This package does not claim any ownership or endorsement rights.


Support

GitHub issues Open new issue

Having an issue, question, or want to contribute?

  1. Check existing issues → Issues page
  2. Not found? Open a new issue

Happy coding! šŸŽ‰