-
Notifications
You must be signed in to change notification settings - Fork 0
/
want.ts
38 lines (29 loc) · 791 Bytes
/
want.ts
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
// GENERATED FILE, DO NOT EDIT
export const post = function<T,U>(path: string, req?: T): Promise<U> {
return new Promise<U>((resolve, reject) => {
const { host, protocol } = window.location
const url = `${protocol}//${host}${path}`
let fetchArg = {
method: 'POST',
credentials: 'same-origin',
} as RequestInit
if (req) {
fetchArg.headers = { 'Content-Type': 'application/json' }
fetchArg.body = JSON.stringify(req)
}
fetch(url, fetchArg).then(resp => resp.json().then(obj => resolve(obj as U)))
})
}
export interface reqType {
A: number
B: string
}
export interface respType {
X: string
Y: number
}
export const Server = {
foo_bar: (req: reqType) => {
return post('/s/foo_bar', req) as Promise<respType>
},
}