-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.ts
More file actions
39 lines (34 loc) · 1.16 KB
/
Example.ts
File metadata and controls
39 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {Api} from "./core/index";
import {DynamicApi, HasDelete, HasGet, HasOptions, HasPatch, HasPost, HasPut} from "./core/ApiTypes";
import {ApiStructureMap} from "./core/StructureTypes";
import axios from 'axios'
type StandardResource = HasOptions & HasGet<any[], any> & HasPost<any, any> & {
[id: string]: HasGet<any, any> & HasPut<any, any> & HasDelete;
}
interface MyApi {
people: HasGet<any[], any> & HasPost & {
(id): HasPut & HasDelete & {
addresses: HasGet<any[], any> & HasPost<any, any> & {
(id): HasDelete & HasPut<any, any>;
}
};
nearMe: HasGet,
me: HasGet & { (id): HasPut }
};
}
let structure = {
people: {
$id: {
addresses: { $id: {} }
},
nearMe: {},
me: { $id: {} }
}
} as ApiStructureMap<MyApi>
// async function doStuff() {
// let api = Api('/api', axios , {structure}) as MyApi;
// let result = await api.people('123').addresses.get({ x: 'hello', y: 'world'});
//
// let dynamic = Api('/api', axios) as DynamicApi;
// let result2 = await dynamic.people['123'].addresses.get({ x: 'hello', y: 'world'});
// }