Created
March 1, 2022 11:22
-
-
Save bbg/422ecb9817a8f567615631c9e551d945 to your computer and use it in GitHub Desktop.
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
import axios from 'axios' | |
type TUsers = { | |
page: number | |
per_page: number | |
total: number | |
total_pages: number | |
data: Array<{ | |
id: number | |
email: string | |
first_name: string | |
last_name: string | |
avatar: string | |
}> | |
} | |
export interface IHttpClientGetParameters<T> { | |
url: string | |
params?: T | |
} | |
const get = async <T>({ ...parameters }: IHttpClientGetParameters<T>): Promise<T> => { | |
return (await axios.get(parameters.url, { params: parameters.params })).data | |
} | |
get<TUsers>({ url: 'https://reqres.in/api/users' }).then((res) => console.log(res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment