@@ -7,6 +7,7 @@ import { useQuery } from 'react-query';
7
7
import { HStack , VStack } from 'native-base' ;
8
8
import { gql , request } from 'graphql-request' ;
9
9
import { CustomButton } from '../../components/CustomButton' ;
10
+ import axios from 'axios' ;
10
11
11
12
export const NetworkScreen : React . FC = ( ) => {
12
13
const [ endpointUrl , setEndpointUrl ] = useState ( '' ) ;
@@ -45,6 +46,32 @@ export const NetworkScreen: React.FC = () => {
45
46
}
46
47
}
47
48
49
+ async function sendRequestToUrlUsingAxios ( ) {
50
+ let urlToSend = '' ;
51
+
52
+ if ( endpointUrl . trim ( ) !== '' ) {
53
+ urlToSend = endpointUrl ;
54
+ console . log ( 'Sending request to: ' , endpointUrl ) ;
55
+ } else {
56
+ // Use json placeholder URL as a default if endpointUrl is empty
57
+ console . log ( 'sending request to default json placeholder' ) ;
58
+ urlToSend = defaultRequestUrl ;
59
+ }
60
+
61
+ try {
62
+ // Perform the request using the urlToSend
63
+ const response = await axios . get ( urlToSend ) ;
64
+ // Format the JSON response for better logging
65
+ const formattedData = JSON . stringify ( response . data , null , 2 ) ;
66
+
67
+ // Log the formatted response
68
+ console . log ( 'Response:' , formattedData ) ;
69
+ } catch ( error ) {
70
+ // Handle errors appropriately
71
+ console . error ( 'Error:' , error ) ;
72
+ }
73
+ }
74
+
48
75
const fetchGraphQlData = async ( ) => {
49
76
const document = gql `
50
77
query {
@@ -75,6 +102,11 @@ export const NetworkScreen: React.FC = () => {
75
102
value = { endpointUrl }
76
103
/>
77
104
< CustomButton onPress = { sendRequestToUrl } title = "Send Request To Url" />
105
+ < CustomButton
106
+ onPress = { sendRequestToUrlUsingAxios }
107
+ title = "Send Request To Url Using Axios"
108
+ />
109
+
78
110
< CustomButton onPress = { ( ) => refetch } title = "Reload GraphQL" />
79
111
< View >
80
112
{ isLoading && < Text > Loading...</ Text > }
0 commit comments