# @breadstone/ziegel-platform-http

[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
[![npm](https://img.shields.io/badge/npm-@breadstone/ziegel--platform--http-red.svg)](https://www.npmjs.com/package/@breadstone/ziegel-platform-http)

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

For detailed API documentation, visit: [API Docs](./../../.docs/api/ziegel-platform-http/index.md)

## Related Packages

- **@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](https://github.com/RueDeRennes/ziegel/issues)

---

*Part of the [ziegel Enterprise TypeScript Framework](../../README.md)*