react-native-simple-fetch
v0.1.3
Published
A simpler implementation of `fetch` for React Native.
Downloads
1
Readme
react-native-simple-fetch
A partial yet simpler implementation of the fetch
API for React Native. Currently iOS only.
Install
Run
npm install --save liaoyuan-io/react-native-simple-fetch
.Add
RCTSimpleFetch.xcodeproj
to your iOS project.Add
libRCTSimpleFetch.a
to yourLink Binary with Libraries
section inBuild Phases
.
Usage
import {fetch} from 'react-native-simple-fetch';
fetch("http://api.blahblah.com/msg/123123123", {
method: 'put', // upper or lower case
headers: {
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
'User-Agent': 'SuperGreatApp/1.0',
},
body: '{"msg": "This is body, possibly text or JSON."}',
gzipRequest: true // Will compress request with gzip.
}).then((res)=>{
console.log("Is OK? ", res.ok);
console.log("Status Code: ", res.status);
return res.json(); // or `res.text();`
}).then((obj)=>{
console.log("Response object is: ", obj);
});