-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: usePromise hook for sending http requests
- Loading branch information
1 parent
688de8c
commit 8ff5415
Showing
16 changed files
with
21,742 additions
and
436 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
API_URL=http://localhost:5096/ | ||
API_URL=http://localhost:3000/ |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
import axios from 'axios'; | ||
import { API_URL } from '@env'; | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
|
||
const api = axios.create({ | ||
baseURL: process.env.API_URL, | ||
baseURL: API_URL + '/api', | ||
}); | ||
|
||
export default api; | ||
const get = <T extends object>( | ||
url: string, | ||
config: AxiosRequestConfig<any> | undefined = undefined, | ||
): Promise<T> => api.get(url, config); | ||
|
||
const del = <T extends object>( | ||
url: string, | ||
config: AxiosRequestConfig<any> | undefined = undefined, | ||
): Promise<T> => api.delete(url, config); | ||
|
||
const post = <T extends object>( | ||
url: string, | ||
data: unknown | undefined = undefined, | ||
config: AxiosRequestConfig<any> | undefined = undefined, | ||
): Promise<T> => api.post(url, data, config); | ||
|
||
const put = <T extends object>( | ||
url: string, | ||
data: unknown | undefined = undefined, | ||
config: AxiosRequestConfig<any> | undefined = undefined, | ||
): Promise<T> => api.put(url, data, config); | ||
|
||
const patch = <T extends object>(url: string, data: unknown): Promise<T> => | ||
api.patch(url, data); | ||
|
||
export { get, del, post, put, patch }; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module '@env' { | ||
export const API_URL: string; | ||
} |
Oops, something went wrong.