@protoarch.angular/api
Version:
Angular HttpClient simplifier
56 lines (55 loc) • 2.05 kB
TypeScript
import { HttpClient, HttpContext, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ISerializer } from './api.options';
import * as i0 from "@angular/core";
export declare enum ResponseTypeEnum {
json = "json",
text = "text",
arraybuffer = "arraybuffer",
blob = "blob"
}
export interface IApiOptions {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
context?: HttpContext;
observe?: any | 'body';
params?: any;
reportProgress?: boolean;
responseType?: any | ResponseTypeEnum;
withCredentials?: boolean;
}
export interface IDeserializeOptions {
/**
* Accepts:
* - constructor: to deserialize to instance of object
* - [constructor] (array with a single element constructor): to deserialize to array of instances
*
* type {({ new(...args): any } | [{ new(...args): any }])}
*
* memberof IDeserializeOptions
*/
deserializeTo?: {
new (...args: any[]): any;
} | [{
new (...args: any[]): any;
}];
}
export declare class Api {
private http;
private apiEndpoint;
private serializer;
constructor(http: HttpClient, apiEndpoint: string | null, serializer: ISerializer);
get<T>(url: string, options?: IApiOptions & IDeserializeOptions): Observable<T>;
post<T>(url: string, body: any, options?: IApiOptions & IDeserializeOptions): Observable<T>;
put<T>(url: string, body: any, options?: IApiOptions & IDeserializeOptions): Observable<T>;
delete<T>(url: string, options?: IApiOptions & IDeserializeOptions): Observable<T>;
download(url: string, triggerBrowserDownload?: boolean, options?: IApiOptions & IDeserializeOptions): Promise<Blob>;
buildUrl(url: string): string;
private buildOptions;
private getHttpParams;
private trySerialize;
private tryDeserialize;
static ɵfac: i0.ɵɵFactoryDeclaration<Api, [null, { optional: true; }, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<Api>;
}