UNPKG

core-native

Version:

A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.

39 lines 1.96 kB
/** * Attention: * Do NOT use "axios" for network utils in React Native. * * Explanation: * 1) Axios supports [nodejs-http] and [XHR] only, does not support [fetch] API. * 2) Although React Native has a XHR-same interface, but it has a bit difference on CORS policy. * 3) If XHR is used in React Native (i.e, what axios does), customized response header cannot be retrieved. * * Ref: * https://stackoverflow.com/questions/37897523/axios-get-access-to-response-header-fields */ export type PathParams<T extends string> = string extends T ? { [key: string]: string | number; } : T extends `${infer Start}:${infer Param}/${infer Rest}` ? { [k in Param | keyof PathParams<Rest>]: string | number; } : T extends `${infer Start}:${infer Param}` ? { [k in Param]: string | number; } : {}; export type Method = "get" | "GET" | "delete" | "DELETE" | "head" | "HEAD" | "options" | "OPTIONS" | "post" | "POST" | "put" | "PUT" | "patch" | "PATCH"; export interface APIErrorResponse { id?: string | null; errorCode?: string | null; message?: string | null; } type RequestHeaderInterceptor = (headers: Headers) => void | Promise<void>; type ResponseHeaderInterceptor = (headers: Headers) => void | Promise<void>; export declare function setRequestHeaderInterceptor(_: RequestHeaderInterceptor): void; export declare function setResponseHeaderInterceptor(_: ResponseHeaderInterceptor): void; export declare function ajax<Request, Response, Path extends string>(method: Method, path: Path, pathParams: PathParams<Path>, request: Request, skipInterceptor?: boolean): Promise<Response>; export declare function uri<Request extends { [key: string]: any; } | null | undefined>(path: string, request: Request): string; export declare function urlParams(path: string, params: object): string; export declare function queryString(params: { [key: string]: any; } | null | undefined): string; export {}; //# sourceMappingURL=network.d.ts.map