Skip to content

Instantly share code, notes, and snippets.

@maroshii
Last active July 31, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maroshii/c263d1a2dadefd5dcd6b560dda31662c to your computer and use it in GitHub Desktop.
Save maroshii/c263d1a2dadefd5dcd6b560dda31662c to your computer and use it in GitHub Desktop.
Sdktor flow type
declare module 'sdktor' {
declare export type Response<T> = { body: T, status: number };
declare export type AsyncResponse<T> = Promise<Response<T>>;
declare type BeforeSend = (reqConfig: {|
path: string,
params: Object,
headers: Object,
|}) => {|
path: string,
params: Object,
headers: Object,
|};
declare type PostRequest = (
res: Response<*>,
ok: boolean
) => Response<*>;
declare export type Hooks = {
beforeSend?: Array<BeforeSend>,
postRequest?: Array<PostRequest>,
};
declare type Factory = (
url: string,
headers?: Object,
options?: Hooks
) => Sdktor;
declare type Verb = (
path: string,
headers?: Object
) => (params: ?Object) => AsyncResponse<*>;
declare export type Sdktor = {|
+at: Factory,
+get: Verb,
+post: Verb,
+put: Verb,
+del: Verb,
+patch: Verb,
+url: () => string,
|};
declare export default Factory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment