/// <reference path="leaf.d.ts" />
declare namespace Leaf {
    interface APICallback<TResult> {
        (error: Error, result: TResult): void;
    }
    interface APIFunction<TOption, TResult> {
        (option: TOption, callback: APICallback<TResult>): void;
        API?: APIDeclare<TOption, TResult>;
    }
    interface APIOption {
        method: string | "GET" | "POST" | "PUT" | "DELETE";
        path: string;
        timeout?: number;
        headers?: any;
        data?: any;
        withCredentials?: boolean;
    }
    class APIFactory {
        option: {
            root?: string;
            prefix?: string;
            suffix?: string;
            dataField?: string;
            errorField?: string;
            defaultTimeout?: number;
            withCredentials?: boolean;
        };
        constructor(option: {
            root?: string;
            prefix?: string;
            suffix?: string;
            dataField?: string;
            errorField?: string;
            defaultTimeout?: number;
            withCredentials?: boolean;
        });
        createAPI<TOption, TResult>(option: APIOption): APIDeclare<TOption, TResult>;
        createAPIFunction<TOption, TResult>(option: APIOption): APIFunction<TOption, TResult>;
        private solveResponse(err, response, callback);
        request<TResult>(option: {
            method?: string;
            url: string;
            query?: any;
            withCredentials?: boolean;
            headers?: any;
            timeout?: number;
        }, callback: {
            (err, result: TResult): void;
        }): XMLHttpRequest;
        buildQueryString(query: any): string;
    }
    class APIDeclare<TOption, TResult> {
        private factory;
        private option;
        constructor(factory: APIFactory, option: APIOption);
        getFunction(): APIFunction<TOption, TResult>;
        invoke(data: TOption, callback: APICallback<TResult>): void;
    }
}
