react-native-http-module
react-native-http-module is a light weight library that provides the functionality to make sample HTTP requests.
WHY react-native-http-module ?
React-native basically uses XHR to make API requests. But the android Wear OS does not support XHR requests. Hence the need to build this custom library has come.
This react-native-http-module library supports HTTP requests in wear OS.
Being promise based is another advantage of this library
GETTING STARTED
$ npm install react-native-http-module --save
MOSTLY AUTOMATIC INSTALLATION
$ react-native link react-native-http-module (in react-native versions <= 60)
CURRENT SUPPORT & USAGE
This react-native-http-module library currently supports/exports the basic methods(get, post & request) to make a API request. The request method supports all the available methods like get, post, delete, put...
; const httpModule = baseURL headers;
This module supports a default constructor that takes the following args:
- baseURL - The application's default endpoint URL. If this is empty, complete endpoint URL given is considered.
- headers - The default headers that can be set for set of upcoming requests.
GET
httpModule;
POST
httpModule;
REQUEST
httpModule;
EXAMPLE
;;; const styles = StyleSheet; const API = { const type setType = ; const url setURL = ; const headers setHeaders = ; const body setBody = ; const response setResponse = ; const sendRequest = { if !url || !type return; ; }; return <View style=stylescontainer> <View style=stylesurlContainer> <Picker selectedValue=type style=stylestype onValueChange= > <PickerItem label="get" value="get" /> <PickerItem label="post" value="post" /> </Picker> <TextInput style=stylesurl onChangeText= value=url placeholder="Enter URL" /> <Button title="SEND" onPress=sendRequest color="orange" /> </View> <Text>Headers</Text> <TextInput style=stylesinputText stylesheaders onChangeText= value=headers /> <Text>Body</Text> <TextInput style=stylesbody stylesinputText onChangeText= value=body /> <Text>Response</Text> <View> <TextInput style=stylesresponse stylesinputText selectable editable=false numberOfLines=20 onChangeText= value=response /> </View> </View> ;};;