import { HttpMethod, RequestConfig, RequestHeaders, QueryParams, QueryParamValue, ContentType, ResponseType, RetryConfig, RequestPriority, RequestMeta } from './types'; /** * Query parameter serialization options */ export interface QuerySerializationOptions { /** Array serialization format */ arrayFormat: 'brackets' | 'indices' | 'repeat' | 'comma'; /** Encode keys */ encodeKeys: boolean; /** Encode values */ encodeValues: boolean; /** Skip null values */ skipNull: boolean; /** Skip undefined values */ skipUndefined: boolean; /** Allow dots in keys for nested objects */ allowDots: boolean; /** Custom serializer for complex types */ serialize?: (key: string, value: unknown) => string | null; } /** * Fluent request builder for constructing type-safe API requests * * @typeParam TResponse - Expected response type * @typeParam TBody - Request body type * * @example * ```typescript * // Simple GET request * const config = new RequestBuilder() * .get('/users/123') * .timeout(5000) * .build(); * * // POST with JSON body * const config = new RequestBuilder() * .post('/users') * .json({ name: 'John', email: 'john@example.com' }) * .build(); * * // Complex query parameters * const config = new RequestBuilder() * .get('/search') * .query({ * q: 'search term', * filters: { status: 'active', type: ['a', 'b'] }, * page: 1, * }) * .build(); * ``` */ export declare class RequestBuilder { private readonly state; private serializationOptions; constructor(); /** * Set HTTP method to GET */ get(url: string): this; /** * Set HTTP method to POST */ post(url: string): this; /** * Set HTTP method to PUT */ put(url: string): this; /** * Set HTTP method to PATCH */ patch(url: string): this; /** * Set HTTP method to DELETE */ delete(url: string): this; /** * Set HTTP method to HEAD */ head(url: string): this; /** * Set HTTP method to OPTIONS */ options(url: string): this; /** * Set custom HTTP method and URL */ method(method: HttpMethod, url: string): this; /** * Set a single path parameter * * @example * ```typescript * builder.get('/users/:userId/posts/:postId') * .pathParam('userId', '123') * .pathParam('postId', '456') * ``` */ pathParam(key: string, value: string | number): this; /** * Set multiple path parameters at once * * @example * ```typescript * builder.get('/users/:userId/posts/:postId') * .pathParams({ userId: '123', postId: '456' }) * ``` */ pathParams(params: Record): this; /** * Set a single query parameter * * @example * ```typescript * builder.get('/users') * .queryParam('page', 1) * .queryParam('limit', 20) * ``` */ queryParam(key: string, value: QueryParamValue): this; /** * Set multiple query parameters at once * * @example * ```typescript * builder.get('/users') * .query({ page: 1, limit: 20, status: 'active' }) * ``` */ query(params: QueryParams): this; /** * Configure query string serialization options * * @example * ```typescript * builder.get('/search') * .queryOptions({ arrayFormat: 'comma' }) * .query({ tags: ['a', 'b', 'c'] }) * // Results in: /search?tags=a,b,c * ``` */ queryOptions(options: Partial): this; /** * Set JSON request body * * @example * ```typescript * builder.post('/users') * .json({ name: 'John', email: 'john@example.com' }) * ``` */ json(data: TBody): this; /** * Set raw body with custom content type */ body(data: TBody, contentType?: ContentType): this; /** * Set text body * * @remarks * Text body is stored as the generic TBody type. When using text(), * ensure TBody is compatible with string or use RequestBuilder. */ text(data: string): RequestBuilder; /** * Initialize multipart form data mode * * @example * ```typescript * builder.post('/upload') * .formData() * .field('title', 'My File') * .file('document', fileBlob) * ``` */ formData(): this; /** * Add a field to form data */ field(name: string, value: string | Blob): this; /** * Add a file to form data * * @example * ```typescript * builder.post('/upload') * .formData() * .file('avatar', imageFile, 'profile.jpg') * ``` */ file(name: string, file: Blob, filename?: string): this; /** * Add multiple files to form data * * @example * ```typescript * builder.post('/upload') * .formData() * .files('attachments', fileList) * ``` */ files(name: string, files: File[] | FileList): this; /** * Set URL-encoded form body * * @remarks * URL-encoded data is stored as a Record. This method * returns a builder typed with the appropriate body type. * * @example * ```typescript * builder.post('/form') * .urlEncoded({ username: 'john', password: 'secret' }) * ``` */ urlEncoded(data: Record): RequestBuilder>; /** * Set a single header * * @example * ```typescript * builder.get('/api') * .header('X-Custom-Header', 'value') * .header('Accept-Language', 'en-US') * ``` */ header(key: string, value: string): this; /** * Set multiple headers at once * * @example * ```typescript * builder.get('/api') * .headers({ * 'X-Custom-Header': 'value', * 'Accept-Language': 'en-US', * }) * ``` */ headers(headers: RequestHeaders): this; /** * Set Accept header */ accept(mimeType: string): this; /** * Set Content-Type header */ contentType(type: ContentType): this; /** * Set Authorization header with Bearer token * * @example * ```typescript * builder.get('/api') * .bearer('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...') * ``` */ bearer(token: string): this; /** * Set Authorization header with Basic auth * * @example * ```typescript * builder.get('/api') * .basicAuth('username', 'password') * ``` */ basicAuth(username: string, password: string): this; /** * Set API key header * * @example * ```typescript * builder.get('/api') * .apiKey('X-API-Key', 'your-api-key') * ``` */ apiKey(headerName: string, key: string): this; /** * Set expected response type * * @example * ```typescript * builder.get('/file') * .responseAs('blob') * ``` */ responseAs(type: ResponseType): this; /** * Expect JSON response (default) */ expectJson(): this; /** * Expect text response */ expectText(): this; /** * Expect blob response */ expectBlob(): this; /** * Expect array buffer response */ expectArrayBuffer(): this; /** * Expect streaming response */ expectStream(): this; /** * Set request timeout in milliseconds * * @example * ```typescript * builder.get('/slow-endpoint') * .timeout(60000) // 60 seconds * ``` */ timeout(ms: number): this; /** * Use short timeout (10s) */ shortTimeout(): this; /** * Use long timeout (2min) */ longTimeout(): this; /** * Set AbortController signal for cancellation * * @example * ```typescript * const controller = new AbortController(); * builder.get('/api') * .signal(controller.signal) * * // Later: controller.abort() * ``` */ signal(signal: AbortSignal): this; /** * Create and return a new AbortController, attaching its signal * * @example * ```typescript * const controller = builder.get('/api') * .abortable() * .build(); * // Later: builder.getAbortController()?.abort() * ``` */ abortable(): this & { getAbortController: () => AbortController; }; /** * Set credentials mode * * @example * ```typescript * builder.get('/api') * .credentials('include') // Send cookies cross-origin * ``` */ credentials(mode: RequestCredentials): this; /** * Include credentials (cookies) */ withCredentials(): this; /** * Omit credentials */ withoutCredentials(): this; /** * Set cache mode * * @example * ```typescript * builder.get('/api') * .cache('no-store') // Never cache * ``` */ cache(mode: RequestCache): this; /** * Disable caching */ noCache(): this; /** * Force fresh response (bypass cache) */ forceRefresh(): this; /** * Configure retry behavior * * @example * ```typescript * builder.get('/unreliable') * .retry({ * maxAttempts: 5, * baseDelay: 2000, * }) * ``` */ retry(config: Partial): this; /** * Set maximum retry attempts */ maxRetries(count: number): this; /** * Disable retries for this request */ noRetry(): this; /** * Set request priority * * @example * ```typescript * builder.get('/critical-data') * .priority('high') * ``` */ priority(level: RequestPriority): this; /** * Mark request as critical priority */ critical(): this; /** * Mark request as background priority */ background(): this; /** * Set custom metadata * * @example * ```typescript * builder.get('/api') * .meta({ feature: 'user-profile', version: 2 }) * ``` */ meta(metadata: Partial): this; /** * Set request tags for categorization * * @example * ```typescript * builder.get('/api') * .tags(['analytics', 'dashboard']) * ``` */ tags(tags: string[]): this; /** * Set idempotency key for safe retries * * @example * ```typescript * builder.post('/orders') * .idempotencyKey('order-123-create') * .json(orderData) * ``` */ idempotencyKey(key: string): this; /** * Set correlation ID for distributed tracing */ correlationId(id: string): this; /** * Skip authentication for this request */ skipAuth(): this; /** * Enable request deduplication */ deduplicate(enabled?: boolean): this; /** * Set cache key for response caching */ cacheKey(key: string): this; /** * Set cache TTL for response caching */ cacheTtl(ttl: number): this; /** * Build the final request configuration * * @returns Complete RequestConfig object ready for execution * * @example * ```typescript * const config = new RequestBuilder() * .get('/users/:id') * .pathParam('id', '123') * .header('Accept-Language', 'en') * .timeout(5000) * .build(); * * // Use with API client * const response = await apiClient.request(config); * ``` */ build(): RequestConfig; /** * Clone the builder with current state */ clone(): RequestBuilder; /** * Build URL with path parameter substitution */ private buildUrl; } /** * Create a new request builder * * @typeParam TResponse - Expected response type * @typeParam TBody - Request body type * * @example * ```typescript * const config = createRequest() * .get('/users/123') * .build(); * ``` */ export declare function createRequest(): RequestBuilder; /** * Create a GET request builder * * @example * ```typescript * const config = get('/users/123') * .query({ include: 'posts' }) * .build(); * ``` */ export declare function get(url: string): RequestBuilder; /** * Create a POST request builder * * @example * ```typescript * const config = post('/users') * .json({ name: 'John' }) * .build(); * ``` */ export declare function post(url: string): RequestBuilder; /** * Create a PUT request builder */ export declare function put(url: string): RequestBuilder; /** * Create a PATCH request builder */ export declare function patch(url: string): RequestBuilder; /** * Create a DELETE request builder */ export declare function del(url: string): RequestBuilder; /** * Serialize query parameters to URL search string * * @example * ```typescript * serializeQueryParams({ page: 1, tags: ['a', 'b'] }) * // Returns: 'page=1&tags[]=a&tags[]=b' * * serializeQueryParams({ page: 1, tags: ['a', 'b'] }, { arrayFormat: 'comma' }) * // Returns: 'page=1&tags=a,b' * ``` */ export declare function serializeQueryParams(params: QueryParams, options?: Partial): string; /** * Parse query string to parameters object * * @example * ```typescript * parseQueryParams('page=1&tags[]=a&tags[]=b') * // Returns: { page: '1', tags: ['a', 'b'] } * ``` */ export declare function parseQueryParams(queryString: string): QueryParams; /** * Build a complete URL with path parameters and query string * * @example * ```typescript * buildUrl('/users/:id/posts', { id: '123' }, { page: 1 }) * // Returns: '/users/123/posts?page=1' * ``` */ export declare function buildUrl(path: string, pathParams?: Record, queryParams?: QueryParams, options?: Partial): string; /** * Join URL segments safely * * @example * ```typescript * joinUrl('https://api.example.com/', '/v1/', 'users') * // Returns: 'https://api.example.com/v1/users' * ``` */ export declare function joinUrl(...segments: string[]): string;