Last active
August 18, 2019 19:42
-
-
Save carlrip/cddaabf14d4b36f29d50accd6837006d to your computer and use it in GitHub Desktop.
Specific functions for different http methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const get = async <T>( | |
path: string, | |
args: RequestInit = { method: "get" } | |
): Promise<IHttpResponse<T>> => { | |
return await http<T>(new Request(path, args)); | |
}; | |
export const post = async <T>( | |
path: string, | |
body: any, | |
args: RequestInit = { method: "post", body: JSON.stringify(body) } | |
): Promise<IHttpResponse<T>> => { | |
return await http<T>(new Request(path, args)); | |
}; | |
export const put = async <T>( | |
path: string, | |
body: any, | |
args: RequestInit = { method: "put", body: JSON.stringify(body) } | |
): Promise<IHttpResponse<T>> => { | |
return await http<T>(new Request(path, args)); | |
}; | |
... | |
// example consuming code | |
const response = await post<{ id: number }>( | |
"https://jsonplaceholder.typicode.com/posts", | |
{ title: "my post", body: "some content" } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment