import { HttpParams, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { DataRequest, DataResult } from '@bootkit/ng1/data'; import * as i0 from '@angular/core'; import { InjectionToken, Provider, EnvironmentProviders } from '@angular/core'; interface HttpRequestOptions { /** Http request ID */ id?: any; params?: HttpParams | Record>; headers?: HttpHeaders | Record; pathType?: 'relative' | 'absolute'; responseType?: 'json' | 'blob' | 'text'; contentType?: 'json' | 'multipart/form-data'; reportProgress?: boolean; observe?: 'response' | 'body' | 'events'; /** * Additional data to associate with this object. */ tag?: Record>; /** * Save response in transfer state * */ transferState?: boolean | { /** * Clear transfer state after first read. */ clearAfterUse?: boolean; }; } /** * HttpDataRequestResolver is a function that takes a URL, a DataRequest, and options, * and returns an Observable that emits a DataResult. * This is used to convert a DataRequest into query parameters or request body for an HTTP request. * @param url The URL to send the request to. * @param dataRequest The DataRequest to convert. * @param options Additional options for the request, such as headers. */ type HttpDataRequestResolver = (url: string, dataRequest: DataRequest, options?: HttpRequestOptions) => Observable>; interface HttpRequestEventBase { type: 'Send' | 'Complete' | 'Progress' | 'Error'; url: string; options?: HttpRequestOptions; } interface HttpRequestSendEvent extends HttpRequestEventBase { type: 'Send'; } interface HttpRequestCompleteEvent extends HttpRequestEventBase { type: 'Complete'; response?: any; } interface HttpRequestProgressEvent extends HttpRequestEventBase { type: 'Progress'; } interface HttpRequestErrorEvent extends HttpRequestEventBase { type: 'Error'; error: any; } type HttpRequestEvent = HttpRequestSendEvent | HttpRequestCompleteEvent | HttpRequestProgressEvent | HttpRequestErrorEvent; /** * HttpService provides a simple HTTP client for making requests. * It supports GET, POST, PUT, DELETE methods and can handle DataRequest objects. * It also supports transfer state for server-side rendering. * It emits events for request lifecycle: Send, Progress, Complete and Error. * It can be configured with a base URL and a default DataRequest resolver. * It can also handle multipart/form-data requests. */ declare class HttpService { private readonly _config; private readonly _http; private readonly _transferState; private readonly _injector; private readonly _platformId; private readonly _eventsSubject; private _baseUrl?; readonly events: Observable; defaultHeaders?: HttpHeaders; constructor(); /** * Sends a GET request to the specified URL. * @param url The URL to send the request to. * @param options The options for the request. * @returns An observable of the response. */ get(url: string, options?: HttpRequestOptions): Observable; /** * Sends a DataRequest to the specified URL and returns a DataResult. * This method is used for paginated or filtered data requests. * It uses the configured DataRequestResolver to handle the request. * @param url The URL to send the request to. * @param request The DataRequest object containing the request parameters. * @param options The options for the request. * @returns An observable of DataResult. */ getDataResult(url: string, request: DataRequest, options?: HttpRequestOptions): Observable>; /** * Sends a POST request to the specified URL with the given body. * @param url The URL to send the request to. * @param body The body of the request. * @param options The options for the request. * @returns An observable of the response. */ post(url: string, body: any, options?: HttpRequestOptions): Observable; /** * Sends a PUT request to the specified URL with the given body. * @param url The URL to send the request to. * @param body The body of the request. * @param options The options for the request. * @returns An observable of the response. */ put(url: string, body: any, options?: HttpRequestOptions): Observable; /** * Sends a DELETE request to the specified URL. * @param url The URL to send the request to. * @param options The options for the request. * @returns An observable of the response. */ delete(url: string, options?: HttpRequestOptions): Observable; private _makeUrl; private _makeBody; private _handleEvents; private _verifyOptions; private _findInTransferState; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Utility function to create FormData from an object. * The function iterates over the properties of the input object and appends them to a FormData instance. * It handles string, File, Blob, number, and nested object types. For nested objects, it stringifies them before appending. * This function is useful for preparing data to be sent in a multipart/form-data request, * especially when dealing with file uploads and complex data structures. * @example * const data = { * name: 'John Doe', * age: 30, * profilePicture: fileInput.files[0], * preferences: { theme: 'dark', notifications: true } * }; * const formData = toFormData(data); * // formData can now be sent in an HTTP request with content type 'multipart/form-data'. * @param data The input object containing the data to be converted into FormData. The properties of this object can be of type string, number, File, Blob, or nested objects. * @returns The FormData instance containing the data from the input object. */ declare function toFormData(data: any): FormData; declare const HTTP_SERVICE_CONFIG: InjectionToken; /** * Configuration for the HttpService. */ interface HttpServiceConfig { /** * Base URL for the HTTP requests. * This is prepended to all request URLs. */ baseUrl?: string; /** * A Resolver function to convert DataRequest to DataResult. */ dataRequestResolver?: HttpDataRequestResolver; } interface HttpServiceFeature { ɵproviders: Array; } /** * Provides the configuration for the HttpService. * @param config * @returns */ declare function provideHttpService(config?: HttpServiceConfig, ...features: Partial[]): EnvironmentProviders; /** * Default implementation of httpDataRequestResolver1. * It adds DataRequest parameters as query string to the HTTP request. * @param url * @param dataRequest * @param options * @template T data item type * @returns */ declare function httpDataRequestResolver1(url: string, dataRequest: DataRequest, options?: HttpRequestOptions): Observable>; export { HTTP_SERVICE_CONFIG, HttpService, httpDataRequestResolver1, provideHttpService, toFormData }; export type { HttpDataRequestResolver, HttpRequestCompleteEvent, HttpRequestErrorEvent, HttpRequestEvent, HttpRequestEventBase, HttpRequestOptions, HttpRequestProgressEvent, HttpRequestSendEvent, HttpServiceConfig, HttpServiceFeature };