Files
free-your-brain/src/core/api/usersTestApi.ts
2021-01-14 11:45:46 +03:00

39 lines
843 B
TypeScript

import {makeApi} from '_utils/makeApi';
import {http} from '_infrastructure/Http';
export type User = {
id: number;
avatar: string;
email: string;
first_name: string;
last_name: string;
};
type Support = {
text: string;
url: string;
};
type UserReponse = {
data: Array<User>;
page: number;
per_page: number;
support: Support;
total: number;
total_pages: number;
};
type UserFindResponse = {
data: User;
support: Support;
}
const ROOT_URL = 'https://reqres.in/api/users';
export const usersApi = makeApi({
request: async () => {
const {data} = await http.get<void, UserReponse>(ROOT_URL);
return data;
},
findById: async (id: string) => {
const {data} = await http.get<void, UserFindResponse>(`${ROOT_URL}/${id}`);
return data;
}
});