File tree 7 files changed +48
-0
lines changed
7 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { api , handlerApiAsync } from "@root/services" ;
2
+
3
+ import { homeBase } from "../utils" ;
4
+
5
+ interface HomeAsyncProps {
6
+ id : number ;
7
+ }
8
+
9
+ export async function getHomeAsync ( { id } : HomeAsyncProps ) {
10
+ const response = await handlerApiAsync ( { execute : ( ) => api . get ( `${ homeBase ( ) } /${ id } ` ) } ) ;
11
+ return response ;
12
+ }
13
+
14
+ export function postHomeAsync ( { id } : HomeAsyncProps ) {
15
+ return api . post ( `${ homeBase ( ) } /${ id } ` ) ;
16
+ }
Original file line number Diff line number Diff line change
1
+ export * from "./homeBase" ;
Original file line number Diff line number Diff line change
1
+ export const homeBase = ( ) => {
2
+ return "/posts" ;
3
+ } ;
Original file line number Diff line number Diff line change
1
+ export * from "./homeBaseUrl" ;
Original file line number Diff line number Diff line change
1
+ import axios from "axios" ;
2
+
3
+ export const api = axios . create ( {
4
+ baseURL : "https://jsonplaceholder.typicode.com/" ,
5
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { AxiosResponse } from "axios" ;
2
+
3
+ interface Props {
4
+ execute : ( ) => Promise < AxiosResponse > ;
5
+ }
6
+
7
+ export const handlerApiAsync = async ( { execute } : Props ) => {
8
+ try {
9
+ const { data } = await execute ( ) ;
10
+ return {
11
+ success : true ,
12
+ data,
13
+ } ;
14
+ } catch ( error ) {
15
+ return {
16
+ success : false ,
17
+ error,
18
+ } ;
19
+ }
20
+ } ;
Original file line number Diff line number Diff line change
1
+ export * from "./api" ;
2
+ export * from "./handlerApi" ;
You can’t perform that action at this time.
0 commit comments