Skip to content

Instantly share code, notes, and snippets.

@mmintel
Last active June 14, 2021 09:55
Show Gist options
  • Save mmintel/3379253a042e2f65a92a35f434249ec5 to your computer and use it in GitHub Desktop.
Save mmintel/3379253a042e2f65a92a35f434249ec5 to your computer and use it in GitHub Desktop.
Typescript HttpService Interface
export interface HttpService {
get<T = any>(url: string, options?: HttpOptions): Promise<T>;
post<T = any>(url: string, data?: {}, options?: HttpOptions): Promise<T>;
patch<T = any>(url: string, data?: {}, options?: HttpOptions): Promise<T>;
put<T = any>(url: string, data?: {}, options?: HttpOptions): Promise<T>;
delete<T = any>(url: string, options?: HttpOptions): Promise<T>;
}
export interface HttpOptions {
params?: HttpParams;
headers?: HttpHeaders;
responseType?: HttpResponseType;
}
export interface HttpParams {
[param: string]: string | string[];
}
export interface HttpHeaders {
[header: string]: string | string[];
}
export type HttpResponseType = 'text' | 'json' | 'arraybuffer' | 'blob';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment