UNPKG

@akala/core

Version:
59 lines (58 loc) 2.15 kB
/// <reference types="node" /> import { ParsedAny } from "./parser"; import { FormatterFactory } from "./formatters/common"; import * as uri from 'url'; import 'isomorphic-fetch'; import { Injected } from "./injector"; export interface HttpOptions { method?: string; url: string | uri.UrlObject; queryString?: any; body?: any; headers?: { [key: string]: string | number | Date; }; contentType?: 'json' | 'form'; type?: 'json' | 'xml' | 'text' | 'raw'; } export interface Http<TResponse = Response> { get(url: string, params?: any): PromiseLike<TResponse>; post(url: string, body?: any): PromiseLike<FormData>; postJSON<T = string>(url: string, body?: any): PromiseLike<T>; getJSON<T>(url: string, params?: any): PromiseLike<T>; invokeSOAP(namespace: string, action: string, url: string, params?: { [key: string]: string | number | boolean; }): PromiseLike<TResponse>; call(options: HttpOptions): PromiseLike<TResponse>; } export declare class FetchHttp implements Http<Response> { constructor(); get(url: string, params?: any): Promise<Response>; post(url: string, body?: any): PromiseLike<FormData>; postJSON<T = string>(url: string, body?: any): PromiseLike<T>; getJSON<T>(url: string, params?: any): PromiseLike<T>; invokeSOAP(namespace: string, action: string, url: string, params?: { [key: string]: string | number | boolean; }): Promise<Response>; call(options: HttpOptions): Promise<Response>; static serialize(obj: any, prefix?: string): any; } export declare class HttpCallFormatterFactory implements FormatterFactory<() => Promise<any>, { method?: keyof Http; }> { constructor(); parse(expression: string): { method?: keyof Http; } & ParsedAny; build(formatter: any, settings: { method: keyof Http; }): Injected<any>; } export declare class HttpFormatterFactory extends HttpCallFormatterFactory implements FormatterFactory<Promise<any>, { method?: keyof Http; }> { constructor(); build(formatter: any, settings: { method: keyof Http; }): (value: any) => any; }