UNPKG

2.15 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ParsedAny } from "./parser";
3import { FormatterFactory } from "./formatters/common";
4import * as uri from 'url';
5import 'isomorphic-fetch';
6import { Injected } from "./injector";
7export interface HttpOptions {
8 method?: string;
9 url: string | uri.UrlObject;
10 queryString?: any;
11 body?: any;
12 headers?: {
13 [key: string]: string | number | Date;
14 };
15 contentType?: 'json' | 'form';
16 type?: 'json' | 'xml' | 'text' | 'raw';
17}
18export interface Http<TResponse = Response> {
19 get(url: string, params?: any): PromiseLike<TResponse>;
20 post(url: string, body?: any): PromiseLike<FormData>;
21 postJSON<T = string>(url: string, body?: any): PromiseLike<T>;
22 getJSON<T>(url: string, params?: any): PromiseLike<T>;
23 invokeSOAP(namespace: string, action: string, url: string, params?: {
24 [key: string]: string | number | boolean;
25 }): PromiseLike<TResponse>;
26 call(options: HttpOptions): PromiseLike<TResponse>;
27}
28export declare class FetchHttp implements Http<Response> {
29 constructor();
30 get(url: string, params?: any): Promise<Response>;
31 post(url: string, body?: any): PromiseLike<FormData>;
32 postJSON<T = string>(url: string, body?: any): PromiseLike<T>;
33 getJSON<T>(url: string, params?: any): PromiseLike<T>;
34 invokeSOAP(namespace: string, action: string, url: string, params?: {
35 [key: string]: string | number | boolean;
36 }): Promise<Response>;
37 call(options: HttpOptions): Promise<Response>;
38 static serialize(obj: any, prefix?: string): any;
39}
40export declare class HttpCallFormatterFactory implements FormatterFactory<() => Promise<any>, {
41 method?: keyof Http;
42}> {
43 constructor();
44 parse(expression: string): {
45 method?: keyof Http;
46 } & ParsedAny;
47 build(formatter: any, settings: {
48 method: keyof Http;
49 }): Injected<any>;
50}
51export declare class HttpFormatterFactory extends HttpCallFormatterFactory implements FormatterFactory<Promise<any>, {
52 method?: keyof Http;
53}> {
54 constructor();
55 build(formatter: any, settings: {
56 method: keyof Http;
57 }): (value: any) => any;
58}