Skip to content

MIT LicenseTypeScriptnpm

HTTP client and web service utilities for the ziegel platform. Provides type-safe HTTP clients, request/response handling, interceptors, and REST API abstractions for enterprise applications.

HTTP Services: Enterprise-grade HTTP client with interceptors, type safety, and advanced request handling.

🚀 Overview

@breadstone/ziegel-platform-http provides:

  • Type-Safe HTTP Client: Strongly typed HTTP requests and responses
  • Request Interceptors: Pre/post request processing
  • Error Handling: Centralized HTTP error management
  • REST API Abstractions: RESTful service client patterns
  • Authentication Support: Built-in auth handling
  • Caching: HTTP response caching mechanisms
  • Retry Logic: Automatic retry with backoff strategies

📦 Installation

bash
npm install @breadstone/ziegel-platform-http
# or
yarn add @breadstone/ziegel-platform-http

🧩 Features & Usage Examples

HTTP Client

typescript
import { HttpClient, HttpMethod } from '@breadstone/ziegel-platform-http';

const client = new HttpClient({
  baseUrl: 'https://api.example.com',
  timeout: 30000,
});

// GET request
const users = await client.get<User[]>('/users');

// POST request
const newUser = await client.post<User>('/users', userData);

Request Interceptors

typescript
import { RequestInterceptor, ResponseInterceptor } from '@breadstone/ziegel-platform-http';

// Add authentication header
client.addRequestInterceptor((config) => {
  config.headers.Authorization = `Bearer ${token}`;
  return config;
});

// Handle responses
client.addResponseInterceptor(
  (response) => response,
  (error) => {
    if (error.status === 401) {
      // Handle unauthorized
    }
    return Promise.reject(error);
  },
);

REST Service Base

typescript
import { RestServiceBase } from '@breadstone/ziegel-platform-http';

class UserService extends RestServiceBase<User> {
  constructor(client: HttpClient) {
    super(client, '/users');
  }

  async getByEmail(email: string): Promise<User> {
    return this.get(`/by-email/${email}`);
  }
}

Error Handling

typescript
import { HttpError, isHttpError } from '@breadstone/ziegel-platform-http';

try {
  const data = await client.get('/api/data');
} catch (error) {
  if (isHttpError(error)) {
    console.log(`HTTP Error: ${error.status} - ${error.message}`);
  }
}

📚 Package import points

typescript
import {
  // HTTP Client
  HttpClient,
  HttpMethod,
  HttpConfig,

  // Interceptors
  RequestInterceptor,
  ResponseInterceptor,

  // Service Base
  RestServiceBase,

  // Error Handling
  HttpError,
  isHttpError,

  // Types
  HttpRequest,
  HttpResponse,
} from '@breadstone/ziegel-platform-http';

📚 API Documentation

  • @breadstone/ziegel-platform: Core platform services
  • @breadstone/ziegel-core: Foundation utilities
  • @breadstone/ziegel-platform-caching: HTTP caching integration

License

MIT

Issues

Please report bugs and feature requests in the Issue Tracker


Part of the ziegel Enterprise TypeScript Framework

Released under the MIT License.