import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { DataMapper } from '@softeq/data-mappers'; import { RequestMethod } from './http.utils'; import { RestSettings } from './rest-settings.service'; /** * Definition of HTTP request operation. */ export interface HttpRequestConfig { method: RequestMethod; url: string; body?: Req; requestMapper?: DataMapper; responseMapper: DataMapper; } /** * Basic class for all REST services. * It provides basic support of operations over HTTP protocol and integration with mappers. */ export declare abstract class AbstractRestService { protected httpClient: HttpClient; private baseUrl; constructor(settings: RestSettings); /** * Rewrites provided url/path in order to add base URL for API endpoints. */ protected url(path: string): string; /** * Performs HTTP request operation based on given config and using provided mappers (from config). */ protected httpRequest(requestConfig: HttpRequestConfig): Observable; /** * Performs GET request and deserialize response using provided mapper * * @param path relative url for endpoint * @param responseMapper mapper for response */ protected httpGet(path: string, responseMapper: DataMapper): Observable; /** * Performs GET request with parameters (via body parameter) and deserialize response using provided mapper. * Body is serialized using provided request mapper. * * @param path relative url for endpoint * @param body body is merged into url using querystring library. * @param requestMapper serializes body. Optional, if mapper is not provided body is used as is. * @param responseMapper mapper for response */ protected httpGet(path: string, body: Req, requestMapper: DataMapper | undefined, responseMapper: DataMapper): Observable; /** * Performs PUT request. * Request and response use the same mapper for serialization of body and deserialization of response correspondingly. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestOrResponseMapper mapper for request and response entity */ protected httpPut(path: string, body: T | undefined, requestOrResponseMapper: DataMapper): Observable; /** * Performs PUT request. This method uses separate mappers to serialize request body and deserialize response. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestMapper mapper for request entity * @param responseMapper mapper for response entity */ protected httpPut(path: string, body: S | undefined, requestMapper: DataMapper, responseMapper: DataMapper): Observable; /** * Performs DELETE request. * Request and response use the same mapper for serialization of body and deserialization of response correspondingly. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestOrResponseMapper mapper for request or response entity */ protected httpDelete(path: string, body: T | undefined, requestOrResponseMapper: DataMapper): Observable; /** * Performs DELETE request. This method uses separate mappers to serialize request body and deserialize response. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestMapper mapper for request entity * @param responseMapper mapper for response entity */ protected httpDelete(path: string, body: S | undefined, requestMapper: DataMapper, responseMapper: DataMapper): Observable; /** * Performs POST request. * Request and response use the same mapper for serialization of body and deserialization of response correspondingly. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestOrResponseMapper mapper for request or response entity */ protected httpPost(path: string, body: T, requestOrResponseMapper: DataMapper): Observable; /** * Performs POST request. This method uses separate mappers to serialize request body and deserialize response. * * @param path relative url for endpoint * @param body entity to be serialized and send * @param requestMapper mapper for request entity * @param responseMapper mapper for response entity */ protected httpPost(path: string, body: S, requestMapper: DataMapper, responseMapper: DataMapper): Observable; }